The Observer pattern class graph. Observer Mode: graph-like observer mode? Php defines the observer call interface classtransfer {protected $ _ observersarray (); registers the object publicfunctionregis observer mode, observer mode class diagram
Observer Mode
_ Observers [] = $ sub;} // calls public function trigger () {if (! Empty ($ this-> _ observers) {foreach ($ this-> _ observers as $ observer) {$ observer-> update ();}}}} // Observer interface obserable {public function update () ;}// implements observer class listen implements obserable {public function update () {echo 'Now first time you need to do listen
';}} Class read implements obserable {public function update () {echo 'Now first time you need to read
';}} Class speak implements obserable {public function update () {echo 'Now first time you need to speak
';}} Class write implements obserable {public function update () {echo 'Now first time you need to write
';}}$ Transfer = new transfer (); $ transfer-> register (new listen (); $ transfer-> register (new read ()); $ transfer-> register (new speak (); $ transfer-> register (new write (); $ transfer-> trigger ();
Observer Mode? Php // defines the observer call interface class transfer {protected $ _ observers = array (); // registers the object public function regis...