Design Patterns in PHP--viewer mode
Observers[] = $observer;} Delete Viewer (person looking at flower) Public Function detach (Observer $observer) {if (In_array ($observer, $this->observers)) {$index = Array_ Search ($observer, $this->observers); unset ($this->observers[$index]); return TRUE;} return false; }//notifies the Observer that public function notify () {foreach ($this->observers as $observer) {$observer->dosometing ()}}} Specific Person class Loveflowerperson implements observer{private $name; function __construct ($sName) {$this->name = $sName ; } public Function dosometing () {echo $this->name. ' Watering flowers ';}} /* Add the First watcher flower */$subject = new Flower (), $observer 1 = new Loveflowerperson (' WLT '); $subject->attach ($observer 1);/* Add a second observer florist */
$observer 2 = new Loveflowerperson (' WLB '); $subject->attach ($observer 2); $subject->notify (); Theme changes, notify Observer Echo ' Delete a florist
'; $subject->detach ($observer 2); $subject->notify (); Subject change, notifying the Observer
http://www.bkjia.com/PHPjc/962643.html www.bkjia.com true http://www.bkjia.com/PHPjc/962643.html techarticle design Pattern in PHP--viewer mode observers[] = $observer;} Delete Viewer (person looking at flowers) public Function detach (Observer $observer) {if (In_array ($observer, $this->observ ...