php责任链模式(The chain of responsibility pattern)
2024-09-04 03:40:25
送家人从火车站归来,继续码。
<?php /* The chain of responsibility pattern decouples the sender of a request from its receiver, by enabling more than one object to handle requests, in a chain manner. Various types of handling objects can be added dynamically to the chain. Using a recursive composition chain allows for an unlimited number of handling objects. */ abstract class SocialNotifier { private $notifyNext = null; public function notifyNext(SocialNotifier $notifyNext) { $this->notifyNext = $notifyNext; return $this->notifyNext; } final public function push($message) { $this->publish($message); if ($this->notifyNext !== null) { $this->notifyNext->push($message); } } abstract protected function publish($message); } class TwitterSocialNotifier extends SocialNotifier { public function publish($message) { echo 'TwitterSocialNotifier_publish' . $message . '<br/>'; } } class FacebookSocialNotifier extends SocialNotifier { protected function publish($message) { echo 'FacebookSocialNotifier_publish' . $message . '<br/>'; } } class PinterestSocialNotifier extends SocialNotifier { protected function publish($message) { echo 'PinterestSocialNotifierr_publish' . $message . '<br/>'; } } $notifier = new TwitterSocialNotifier(); $notifier->notifyNext(new FacebookSocialNotifier()) ->notifyNext(new PinterestSocialNotifier()); $notifier->push('Awesome new product availiable.') ?>
最新文章
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(81)-数据筛选(万能查询)
- 简单CSS3实现炫酷读者墙
- 1.Dotnet Core安装
- 命令安装VS
- Python 5 —— OOP
- spring data实现自定义的repository实现类,实现跟jpa联通
- Linux之磁盘管理
- Android SDK 更新失败
- Webform和MVC,为什么MVC更好一些?
- CSS3 grayscale滤镜图片变黑白实例页面
- 《高质量程序设计指南:C++/C语言》面试题整理
- 一旦rhel5.8造成只读文件系统ORA-00354: corrupt redo log block header
- oracle 数据库安装环境,需要大汇总
- java 并发多线程异步
- RPM安装软件
- ajax和axios、fetch的区别
- iOS UILabel 文字 置顶/置底 实现
- C++ 函数模板默认的模板参数
- Spark 论文篇-论文中英语单词集
- Mysql 视图使用