志在指尖
用双手敲打未来

PHP设计桥接模式

<?php
/**
*@Description:桥接模式
*@Author:luoxiaojin
*@Date:2020-06-3010:06:41
*@LastEditors:luoxiaojin
*@LastEditTime:2020-06-3011:00:04
*@FilePath:\design_patterns\l10.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();

未经允许不得转载:IT技术网站 » PHP设计桥接模式
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

志在指尖 用双手敲打未来

登录/注册IT技术大全

热门IT技术

C#基础入门   SQL server数据库   系统SEO学习教程   WordPress小技巧   WordPress插件   脚本与源码下载