Re: RFC: Custom Factories (SPL)
| From: | Mathieu Suen | Date: | Thu, 19 Nov 2009 15:17:10 +0000 |
| Subject: | Re: RFC: Custom Factories (SPL) | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-46106@lists.php.net to get a copy of this message | ||
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:-- • *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é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