note 112122 added to class.splsubject
| From: | Anonymous | Date: | Tue, 07 May 2013 10:37:46 +0000 |
| Subject: | note 112122 added to class.splsubject | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194726@lists.php.net to get a copy of this message | ||
<?php
class Observable implements SplSubject
{
private $storage;
function __construct()
{
$this->storage = new SplObjectStorage();
}
function attach(SplObserver $observer)
{
$this->storage->attach($observer);
}
function detach(SplObserver $observer)
{
$this->storage->detach($observer);
}
function notify()
{
foreach ($this->storage as $obj) {
$obj->update($this);
}
}
//...
}
abstract class Observer implements SplObserver
{
private $observable;
function __construct(Observable $observable)
{
$this->observable = $observable;
$observable->attach($this);
}
function update(SplSubject $subject)
{
if ($subject === $this->observable) {
$this->doUpdate($subject);
}
}
abstract function doUpdate(Observable $observable);
}
class ConcreteObserver extends Observer
{
function doUpdate(Observable $observable)
{
//...
}
}
$observable = new Observable();
new ConcreteObserver($observable);
----
Server IP: 69.147.83.199
Probable Submitter: 178.124.31.174
----
Manual Page -- http://php.net/manual/en/class.splsubject.php
Edit -- https://master.php.net/note/edit/112122
Del: integrated -- https://master.php.net/note/delete/112122/integrated
Del: useless -- https://master.php.net/note/delete/112122/useless
Del: bad code -- https://master.php.net/note/delete/112122/bad+code
Del: spam -- https://master.php.net/note/delete/112122/spam
Del: non-english -- https://master.php.net/note/delete/112122/non-english
Del: in docs -- https://master.php.net/note/delete/112122/in+docs
Del: other reasons-- https://master.php.net/note/delete/112122
Reject -- https://master.php.net/note/reject/112122
Search -- https://master.php.net/manage/user-notes.php