您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
设计模式-桥接模式
发布时间:2017-11-30 09:25:07编辑:雪饮阅读()
<?php
header('content-type:text/html;charset=utf-8');
//信息抽象类
abstract class info{
protected $send=null;
public function __construct($send){
$this->send=$send;
}
abstract public function msg($content);
public function send($to,$content){
$content=$this->msg($content);
$this->send->send($to,$content);
}
}
//信息的不同发送方式
//站内信息
class zn{
public function send($to,$content){
echo '站内给'.$to.'内容是:'.$content;
}
}
//email信息
class email{
public function send($to,$content){
echo 'email给'.$to.'内容是:'.$content;
}
}
//sms信息
class sms {
public function send($to,$content){
echo 'sms给'.$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('小刚','中500万了,快回家');
?>
关键字词:设计模式,桥接模式
上一篇:设计模式-面向接口开发
下一篇:设计模式-适配器模式