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

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."发送站内信:
".$content; } } /** * email信 */ class EmailMsg { public function send($to, $content) { echo "".$to."发送Email:
".$content; } } /** * sms信 */ class SmsMsg { public function send($to, $content) { echo "".$to."发送短信:
".$content; } } // 内容分为普通,加急,特急三种程度 /** * 普通 */ class CommonInfo extends msg { public function msg($content) { return "普通:".$content."
"; } } /** * 加急 */ class WarnInfo extends msg { public function msg($content) { return "加急:".$content."
"; } } /** * 特急 */ class DangerInfo extends msg { public function msg($content) { return "特急:".$content."
"; } } $DangerInfo = new DangerInfo(new EmailMsg()); $DangerInfo->send('小小','不要再去参加极限运动了'); $WarnInfo = new WarnInfo(new EmailMsg()); $WarnInfo->send('毛毛','马上过来办公室开会!');

你可能感兴趣的:(php设计模式之桥接模式实例代码)