Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 1
    A factory pattern should take care of injecting it in objects at instantiation (seperate instantiation / building object trees from business logic, rule of thumb if there is no 'inline' new except for in clear factories). Commented Jul 4, 2012 at 17:40
  • @Wrikken -- that makes sense to me in theory, just not entirely sure how I would go about doing it, could you give me an example of the factory method? Is the factory called statically? Or is the factory a singleton? Commented Jul 4, 2012 at 17:48
  • 1
    Ideally, from a testing point of view, you probably want instance methods, but it is hard not to fall into the trap of making everything accessible through that instance, making in essence everything global. I could very well live with 'main' objects created statically, but at a point, the Factory (or a specific subfactory) itself is something you also inject into your objects. This becomes abstract very quickly :P Commented Jul 4, 2012 at 18:14
  • @ Wrikken -- do you have a code example? A bit much for me to wrap my head around :) Commented Jul 4, 2012 at 20:26