送家人从火车站归来,继续码。

<?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.')

?>

最新文章

  1. ASP.NET MVC5+EF6+EasyUI 后台管理系统(81)-数据筛选(万能查询)
  2. 简单CSS3实现炫酷读者墙
  3. 1.Dotnet Core安装
  4. 命令安装VS
  5. Python 5 —— OOP
  6. spring data实现自定义的repository实现类,实现跟jpa联通
  7. Linux之磁盘管理
  8. Android SDK 更新失败
  9. Webform和MVC,为什么MVC更好一些?
  10. CSS3 grayscale滤镜图片变黑白实例页面
  11. 《高质量程序设计指南:C++/C语言》面试题整理
  12. 一旦rhel5.8造成只读文件系统ORA-00354: corrupt redo log block header
  13. oracle 数据库安装环境,需要大汇总
  14. java 并发多线程异步
  15. RPM安装软件
  16. ajax和axios、fetch的区别
  17. iOS UILabel 文字 置顶/置底 实现
  18. C++ 函数模板默认的模板参数
  19. Spark 论文篇-论文中英语单词集
  20. Mysql 视图使用

热门文章

  1. 第8课 常量表达式(constexpr)
  2. beego:限制接口访问频率
  3. Redis的LRU算法
  4. Spring Boot 嵌入式 Tomcat 文件上传、url 映射虚拟路径
  5. 如何解决Requests的SSLError(转)
  6. CSP-S2019 自闭记
  7. Centos7通过yum安装jdk8
  8. maven添加本地包命令mvn install:install-file
  9. Redis和数据库一致性
  10. dotnet core系列之Background tasks with hosted services (后台任务)