abstract class info{
public $msgClass = null;
public function __construct($obj){
$this->msgClass = $obj;
}
abstract function msg();
public function send($to,$content){
return $this->msg() . $this->msgClass->send($to,$content);
}
}
//QQ信息
class qq_msg{
public function send($to,$content){
return '【QQ消息】发送给:'.$to.',内容:'.$content;
}
}
//邮件信息
class email_msg{
public function send($to,$content){
return '【Email消息】发送给:'.$to.',内容:'.$content;
}
}
//短信消息
class sms_msg{
public function send($to,$content){
return '【短信消息】发送给:'.$to.',内容:'.$content;
}
}
//普通消息
class common_info extends info{
public function msg(){
return '【普通】';
}
}
//警告消息
class warning_info extends info{
public function msg(){
return '【警告】';
}
}
//危急消息
class danger_info extends info{
public function msg(){
return '【危急】';
}
}
$a = new common_info(new email_msg());
$res = $a->send('zhang san','好好学习');
var_dump($res);
$a = new warning_info(new sms_msg());
$res = $a->send('zhang san','好好学习');
var_dump($res);