• 桥接模式


    <?php
    //桥接模式
    abstract class info {
        protected $send = null;
        
        public function __construct(Send $send){
            $this->send = $send;
        }
        
        abstract public function msg($content);
        public function send($to,$content){
            $content = $this->msg($content);
            $this->send->send($to,$content);
        }
    }
    
    interface Send {
        public function send($to,$content);
    }
    class zn implements Send {
        public function send($to,$content){
            echo '站内给' . $to .',内容是:' . $content;
        }
    }
    
    class email implements Send {
        public function send($to,$content){
            echo 'email给' . $to .',内容是:' . $content;
        }
    }
    
    class sms implements Send {
        public function send($to,$content){
            echo '短信给' . $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('小刚','你家失火了');
  • 相关阅读:
    PHP简单工厂模式、工厂方法模式和抽象工厂模式
    PHP的HashTable实现
    理解Hash
    PHP中Array的hash函数实现
    R-FCN论文讲解(转载链接)
    目标检测的发展历程
    K-means算法
    pytorch0.4.1安装
    反卷积(deconvolution)
    faster-rcnn自己的理解总结(包括它的前世今身R-CNN和fast R-CNN)
  • 原文地址:https://www.cnblogs.com/nr-zhang/p/10950635.html
Copyright © 2020-2023  润新知