<?php
/**
*@Description:桥接模式
*@Author:luoxiaojin
*@Date:2020-06-3010:06:41
*@LastEditors:luoxiaojin
*@LastEditTime:2020-06-3011:00:04
*@FilePath:design_patternsl10.php
*/
//论坛发送站内信
abstractclassMsg{
//发送方式
protected$send=null;
//发送内容
protected$text=”;
publicfunctioncontent(){
//
}
publicfunctionsend(){
//
}
}
//发送方式
classEmailMsgextendsMsg{
publicfunction__construct($to,$text){
$this->text=$to.$text;
}
publicfunctioncontent(){
return’Email:’.$this->text;
}
}
classSmsMsgextendsMsg{
publicfunction__construct($to,$text){
$this->text=$to.$text;
}
publicfunctioncontent(){
return’短信:’.$this->text;
}
}
//紧急程度
classCommonSendextendsMsg{
publicfunction__construct(Msg$obj){
$this->text=$obj->content();
}
publicfunctionsend(){
return”{$this->text},普通信息!”;
}
}
classUrgentSendextendsMsg{
publicfunction__construct(Msg$obj){
$this->text=$obj->content();
}
publicfunctionsend(){
return”{$this->text},紧急通知!”;
}
}
//耦合调用
$commonEmailMsg=newCommonSend(newEmailMsg(‘小明’,’吃饭了!’));
echo$commonEmailMsg->send();
$urgentSmsMsg=newUrgentSend(newSmsMsg(‘小红’,’家里失火了!’));
echo$urgentSmsMsg->send();
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。