Re: RFC: Custom Factories (SPL)
| From: | Ionut G. Stan | Date: | Thu, 19 Nov 2009 15:07:27 +0000 |
| Subject: | Re: RFC: Custom Factories (SPL) | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-46105@lists.php.net to get a copy of this message | ||
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).
It's a basic application of 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-- Ionut G. Stan I'm under construction | http://blog.igstan.ro/