zoukankan      html  css  js  c++  java
  • 桥接模式

    <?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('小刚','你家失火了');
  • 相关阅读:
    generator
    JS 中 apply 、call 、bind的详解
    前端面试题(24-js)
    JS原型链深入了解
    Java12新特性
    Java11-ZGC
    Java11新特性
    Java10新特性
    Java9新特性
    CF1385E【Directing Edges】 (拓扑排序)
  • 原文地址:https://www.cnblogs.com/nr-zhang/p/10950635.html
Copyright © 2011-2022 走看看