美文网首页
桥接模式

桥接模式

作者: 散装咖啡 | 来源:发表于2017-05-30 03:02 被阅读1次
    /**
    * bridge模式
    *
    * 将抽象部份与它实现部分分离,使用它们都可以有独立的变化
    */
    
        abstract class Implementor
        {
            abstract public function operation();
        }
    
        class ConcreteImplementorA extends Implementor
        {
            public function operation()
            {
                echo "ConcreteImplementorA Operation<br/>";
            }
        }
    
        class ConcreteImplementorB extends Implementor
        {
            public function operation()
            {
                echo "ConcreteImplementorB Operation<br/>";
            }
        }
    
        class Abstraction
        {
            protected $_implementor = null;
            
            public function setImplementor($implementor)
            {
                $this->_implementor =$implementor;
            }
            
            public function operation()
            {
                $this->_implementor->operation();
            }
        }
    
        class RefinedAbstraction extends Abstraction
        {
            
        }
    
        class ExampleAbstraction extends Abstraction
        {
            
        }
    
        
    $objRAbstraction = new RefinedAbstraction();
    $objRAbstraction->setImplementor(new ConcreteImplementorB());
    $objRAbstraction->operation();
    $objRAbstraction->setImplementor(new ConcreteImplementorA());
    $objRAbstraction->operation();
    
    $objEAbstraction = new ExampleAbstraction();
    $objEAbstraction->setImplementor(new ConcreteImplementorB());
    $objEAbstraction->operation();
    

    参考文章 https://wenku.baidu.com/view/b4c78b4702768e9951e738fb.html

    相关文章

      网友评论

          本文标题:桥接模式

          本文链接:https://www.haomeiwen.com/subject/cjglfxtx.html