首页 > Web开发 > 详细

php设计模式之桥接模式实例代码

时间:2020-01-12 19:35:33      阅读:86      评论:0      收藏:0      [点我收藏+]
<?php 
header("Content-type:text/html;charset=utf-8");

abstract class msg{
    protected $send = null;
    public function __construct($send){
        $this->send = $send;
    }
    abstract function msg($content);

    function send($to, $content){
        $content = $this->msg($content);
        $this->send->send($to, $content);
    }
}

/**
* 普通信
*/
class ZnMsg
{
    public function send($to, $content)
    {
        echo "".$to."发送站内信:<br>".$content;
    }
}

/**
* email信
*/
class EmailMsg
{
    public function send($to, $content)
    {
        echo "".$to."发送Email:<br>".$content;
    }
}

/**
* sms信
*/
class SmsMsg
{
    public function send($to, $content)
    {
        echo "".$to."发送短信:<br>".$content;
    }
}

// 内容分为普通,加急,特急三种程度

/**
* 普通
*/
class CommonInfo extends msg
{
    
    public function msg($content)
    {
        return "普通:".$content."<br>";
    }
}

/**
* 加急
*/
class WarnInfo extends msg
{
    
    public function msg($content)
    {
        return "加急:".$content."<br>";
    }
}

/**
* 特急
*/
class DangerInfo extends msg
{
    
    public function msg($content)
    {
        return "特急:".$content."<br>";
    }
}

$DangerInfo = new DangerInfo(new EmailMsg());
$DangerInfo->send(小小,不要再去参加极限运动了);

$WarnInfo = new WarnInfo(new EmailMsg());
$WarnInfo->send(毛毛,马上过来办公室开会!);

php设计模式之桥接模式实例代码

原文:https://www.cnblogs.com/Mishell/p/12183257.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!