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

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

?>

php责任链模式(The chain of responsibility pattern)的更多相关文章

  1. 【设计模式】行为型05责任链模式(Chain of responsibility Pattern)

    学习地址:http://www.runoob.com/design-pattern/chain-of-responsibility-pattern.html demo采用了DEBUG级别举例子,理解起 ...

  2. 23种设计模式之责任链模式(Chain of Responsibility Pattern)

    责任链模式(Chain of Responsibility Pattern)为请求创建了一个接收者对象的链.这种模式给予请求的类型,对请求的发送者和接收者进行解耦.这种类型的设计模式属于行为型模式. ...

  3. 第 17 章 责任链模式【Chain of Responsibility Pattern】

    以下内容出自:<<24种设计模式介绍与6大设计原则>> 中国古代对妇女制定了“三从四德”的道德规范,“三从”是指“未嫁从父.既嫁从夫.夫死从子”,也就是说一个女性,在没有结婚的 ...

  4. 责任链模式(Chain of Responsibility Pattern)

    责任链模式:可以为某个请求创建一个对象链.每个对象依序检查此请求,并对其处理,或者把它传给链中的下一个对象. 责任链上的对象负责处理请求,客户只需要将请求发送到责任链上即可,无需关心处理的细节和请求的 ...

  5. 责任链模式(Chain of Responsibility)

    责任链模式(Chain of Responsibility)接下来我们将要谈谈责任链模式,有多个对象,每个对象持有对下一个对象的引用,这样就会形成一条链,请求在这条链上传递,直到某一对象决定处理该请求 ...

  6. Java设计模式(14)责任链模式(Chain of Responsibility模式)

    Chain of Responsibility定义:Chain of Responsibility(CoR) 是用一系列类(classes)试图处理一个请求request,这些类之间是一个松散的耦合, ...

  7. 19.职责链模式(Chain of Responsibility Pattern)

    19.职责链模式(Chain of Responsibility Pattern)

  8. 深入浅出设计模式——职责链模式(Chain of Responsibility Pattern)

    模式动机 职责链可以是一条直线.一个环或者一个树形结构,最常见的职责链是直线型,即沿着一条单向的链来传递请求.链上的每一个对象都是请求处理者,职责链模式可以将请求的处理者组织成一条链,并使请求沿着链传 ...

  9. 【设计模式 - 13】之责任链模式(Chain Of Responsibility)

    1      模式简介 责任链模式的简介: 1.        责任链模式为请求创建了一个接收者对象的链,每个接收者都包含对另一个接收者的引用,如果一个对象不能处理该请求,那么它会把相同的请求传给下一 ...

随机推荐

  1. 【IntelliJ IDEA学习之七】maven专题

    版本:IntelliJIDEA2018.1.4 一.maven全局设置 设置Runner 运行VM参数:-Xms128m -Xmx512m -Duser.language=zh -Dfile.enco ...

  2. 017 使用域名访问本地项目---涉及switchhost和Nginx

    1.统一环境 我们现在访问页面使用的是:http://localhost:9001 实际开发中,会有不同的环境: 开发环境:自己的电脑 测试环境:提供给测试人员使用的环境 预发布环境:数据是和生成环境 ...

  3. Springboot Actuator之七:actuator 中原生endpoint源码解析1

    看actuator项目的包结构,如下: 本文中的介绍Endpoints. Endpoints(端点)介绍 Endpoints 是 Actuator 的核心部分,它用来监视应用程序及交互,spring- ...

  4. poi根据excel模板导出Excel

    /****单元格值对象**/public class Cells { /*** * 行 */ private int row; /** * 列 */ private int column; /** * ...

  5. fiddle4 弱网测试

    下载:https://www.telerik.com/download/fiddler/fiddler4 参考:https://blog.csdn.net/qq_28905427/article/de ...

  6. c/c++封装成python包

    参考网址:https://blog.csdn.net/tiankongtiankong01/article/details/80420033 SWIG (Simplified Wrapper and ...

  7. docker封装mysql镜像

    一.概述 直接使用官方的镜像 docker pull mysql:5.7 但是mysqld.cnf并没有优化,还是默认的. 二.封装镜像 创建目录 # dockerfile目录 mkdir -p /o ...

  8. 使用git svn clone迁移svn仓库(保留提交记录)

    使用git svn clone迁移svn仓库 clone命令可以指定很多参数,主要用到这些,你也可以使用git svn help查看完整的参数列表. git svn clone https://172 ...

  9. 基于百度地图JavaScript API,员工住址统计

    公司一般都有通讯和住址的统计,但是文字化的表格根本就不知道住在哪. 用百度地图就可以轻松解决, 而且公司还经常人员变动,读取excel中的内容,就不用每次还要更改地图文件了. 在遇到需要聚餐在地图中标 ...

  10. ubuntu开发常用收集

    命令: 1.http://blog.csdn.net/simongeek/article/details/45271089 2.http://www.jianshu.com/p/654be9c0f13 ...