当前位置:首页 > Web开发 > 正文

‘ 马上过来办公室开会! ‘ ); php设计模式之桥接模式实例代码

2024-03-31 Web开发

<?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设计模式之桥接模式实例代码

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/31722.html