Code: Select all
$obj = new $className;Moderator: General Moderators
Code: Select all
$obj = new $className;Hmm, that's an interesting question. A good way to figure out when is to ask yourself what the consequences of using a factory are (ripped from GoF)So what signs indicate to you that you should consider a object factory of one sort or another?
Code: Select all
$obj = $this->newClassName();If you're a stickler about dependencies to interfaces not implementations, yes. Once again, however, it doesn't have to be an object factory, it can be a factory method.If one class instantiates another should you do it with a factory?
Yes. Use your good judgment. The golden rule of refactoring: the first time, just do it. The second time, do it but cringe. The third time, refactor!Can you have factoryitis?
This is more reflection, so whether or not to use a factory is up to you. I would.Should you use a factory if the name of the class being instantiated is dynamically class