Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'll be honest, and I know others disagree, but I find that abstracting class instantiation into XML or a database to be a horrible idea. I'm a fan of making code crystal clear even if it sacrifices some flexibility. The downsides I see are:</p> <ul> <li>It is hard to trace through code and find where objects are created.</li> <li>Other people working on the project are required to understand your proprietary format for instantiating objects.</li> <li>On small projects you will spend more time implementing dependency injection that you will actually switching around classes.</li> <li>You won't be able to tell what's being created until runtime. That's a debugging nightmare, and your debugger won't like you for it either.</li> </ul> <p>I'm actually a bit tired of hearing about this particular programming fad. It feels and looks ugly, and it solves a problem that few projects need to have solved. Seriously, how often are you going to be adding and removing sodas from that code. Unless it's practically every time you compile then there's so little advantage with so much extra complxexity.</p> <p>Just to clarify, I think that inversion of control can be a good design idea. I just don't like having code externally embedded just for instantiation, in XML or otherwise.</p> <p>The switch-case solution is fine, as that's one way of implementing the factory pattern. Most programmers won't be hard pressed to understand it. It's also more clearly organized than instantiating subclasses all around your code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload