Ionut G. Stan a écrit :
One could just as well pass an instance of Emailer to the constructor. It's the same thing, except that it's less code (and it's easier to understand in my opinion).

That is type 3 IoC.



It's a basic application of the Law of Demeter.

I don't see the point with "the Law of Demeter"?


On 11/18/2009 7:19 PM, Mathieu Suen wrote:

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();
// ...
}
}
-- Mathieu Suen



--
        

• *Mathieu Suen* | It Team | www.easyflirt.com
• mathieu [dot] suen [at] easyflirt [dot] com
• EasyFlirt - Park Nord, Les Pléiades, 74370 - Metz-Tessy - FRANCE


• Pensez à l'environnement, n'imprimez cet e-mail qu'en cas de réelle
nécessité


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to