zoukankan      html  css  js  c++  java
  • PHP设计模式——桥接模式

    <?php
    
    /*
     * 桥接模式
     * 使用发送器,将一个类对象传入另一个类作为属性,耦合M+N个类
     * 
     */
    
    abstract class Info {
    
        protected $_send = NULL;
    
        public function __construct($send) {
            $this->_send = $send;
        }
    
        abstract function msg($content);
    
        public function send($to, $content) {
            $content = $this->msg($content);
            $this->_send->send($to, $content);
        }
    
    }
    
    class Email {
    
        public function send($to, $content) {
            echo "Email: From:$to Content:$content<br>";
        }
    
    }
    class Sms {
    
        public function send($to, $content) {
            echo "Sms: From:$to Content:$content<br>";
        }
    
    }
    
    class CommonBridge extends Info{
        public function msg($content) {
            return 'CommonBridge>>'.$content;
        }
    }
    class DangerBridge extends Info{
        public function msg($content) {
            return 'DangerBridge>>'.$content;
        }
    }
    //调用桥接
    $email = new Email();
    $CommonEmail  = new CommonBridge($email);
    $CommonEmail->send('Tom','XXXXX');
    
    $DangerSms  = new DangerBridge(new Sms());
    $DangerSms->send('Lucy','OOOOOOO');
  • 相关阅读:
    sqlsever2008及以上各个安装包的说明
    解决 windows2012 下无法安装 sql2008R2
    dapper extensions (predicates)
    Dapper full example
    Dapper.ColumnMapper 的使用
    wms
    大端格式 与 小端格式
    mysql数据库引擎
    事务
    MySQL索引底层实现
  • 原文地址:https://www.cnblogs.com/tlxma/p/5210719.html
Copyright © 2011-2022 走看看