Design Patterns bridge mode php example code

<?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 the send ($ to, $ Content) 
    { 
        echo " to " $ to.. " Send SMS: <br> " $ Content;. 
    } 
} 

// content is divided into ordinary, urgent, three degrees Express 

/ * * 
* normal 
* / 
class CommonInfo the extends MSG 
{ 
    
    public function MSG (Content $) 
    { 
        return  " normal: " $ Content.. " <br> " ; 
    } 
} 

/ * * 
* urgent 
* / 
class WarnInfo the 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('小小','Do not go to the extreme sports ' ); 

$ WarnInfo = new new WarnInfo ( new new emailmsg ()); 
$ WarnInfo -> the send ( ' hairy ' , ' right over office meeting! ' );

Guess you like

Origin www.cnblogs.com/Mishell/p/12183257.html