Py-notify has much more to offer on top of the signals concept, but I'm currently only interested in the pure observer concept and partially ported it to php. code/examples
Here is an simple Observer example:
class Observer {
function notify($msg) {
echo "Subject says: $msg\n";
}
}
class Subject {
/**
* @var ekn_Signal
*/
protected $signal;
function __construct() {
$this->signal = new ekn_Signal();
}
function addObserver($observer, $method = 'notify') {
$this->signal->connect(array($observer, $method));
}
function saySomething() {
$this->signal->emit('something');
}
}
$subject = new Subject();
$subject->addObserver(new Observer());
$subject->saySomething();
No comments:
Post a Comment