Hi Mathieu, Am 18.11.2009 um 18:19 schrieb Mathieu Suen:
> Right!! > I get confused with: > $classNamme::getInstance(); > > So you can easily inject dependency: > > class Foo { > > protected $emailer; > > public function __construct($emailClass) { > $this->emailer= $emailClass; > } > > public function bar() { > // $email = new $this->emailer(); Of course not allowed > $emailer = $this->emailer; > $email = $emailer(); > // ... > } > } Well, this won't work, because Foo surely doesn't have all the knowledge to automatically resolve dependencies for the Email implementation. What if Email needs some SMTP Service injected? Foo won't know. Therefore it's much better to let some specialized Object Factory to do the task. Letting Foo instantiate an Email would be asking a car to build its engine. Better delegate that task to a factory ... Cheers, robert -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php