桥接模式
<?php //桥接模式 abstract class info { protected $send = null; public function __construct(Send $send){ $this->send = $send; } abstract public function msg($content); public function send($to,$content){ $content = $this->msg($content); $this->send->send($to,$content); } } interface Send { public function send($to,$content); } class zn implements Send { public function send($to,$content){ echo '站内给' . $to .',内容是:' . $content; } } class email implements Send { public function send($to,$content){ echo 'email给' . $to .',内容是:' . $content; } } class sms implements Send { public function send($to,$content){ echo '短信给' . $to .',内容是:' . $content; } } class commoninfo extends info { public function msg($content){ return '普通' . $content; } } class warninfo extends info { public function msg($content){ return '紧急' . $content; } } class dangerinfo extends info { public function msg($content){ return '特急' . $content; } } //站内发普通信息 $commoninfo = new commoninfo(new zn()); $commoninfo->send('小明','吃饭了'); echo '<br />'; //用手机发特急信息 $dangerinfo = new dangerinfo(new sms()); $dangerinfo->send('小刚','你家失火了');