企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
英语单词 observer观察者 notify通知 <?php interface Subject { public function register(Observer $observer); public function notify(); } interface Observer { public function watch(); } class Action implements Subject { public $_observers=array(); public function register(Observer $observers) { $this->_observers[]=$observers; } public function notify() { foreach ($this->_observers as $observer) { $observer->watch(); } } } class Cat implements Observer{ public function watch(){ echo "Cat watches TV<hr/>"; } } class Dog implements Observer{ public function watch(){ echo "Dog watches TV<hr/>"; } } class People implements Observer{ public function watch(){ echo "People watches TV<hr/>"; } } $action=new Action(); $action->register(new Cat()); $action->register(new People()); $action->register(new Dog()); $action->notify();