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/


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

Reply via email to