class Paper{ private $instance = array(); //注册观察者 public function register($obj){ $this->instance[] = new $obj; } public function trigger(){ if (!empty($this->instance)){ foreach ($this->instance as $observer){ $observer->update(); } } } } interface observer{ public function update(); } class subversion implements observer{ public function update(){ echo "wobeiguanchaleppppp"; } } $paper = new Paper(); $paper->register(new subversion()); $paper->trigger();
分类:PHP
标签: