zoukankan      html  css  js  c++  java
  • [php]php设计模式 Bridge (桥接模式)

    1 <?php
    2 /**
    3 * 桥接模式
    4 *
    5 * 将抽象部份与它实现部分分离,使用它们都可以有独立的变化
    6 */
    7 abstractclass Implementor
    8 {
    9 abstractpublicfunction operation();
    10 }
    11
    12 class ConcreteImplementorA extends Implementor
    13 {
    14 publicfunction operation()
    15 {
    16 echo"ConcreteImplementorA Operation<br/>";
    17 }
    18 }
    19
    20 class ConcreteImplementorB extends Implementor
    21 {
    22 publicfunction operation()
    23 {
    24 echo"ConcreteImplementorB Operation<br/>";
    25 }
    26 }
    27
    28 class Abstraction
    29 {
    30 protected$_implementor=null;
    31
    32 publicfunction setImplementor($implementor)
    33 {
    34 $this->_implementor =$implementor;
    35 }
    36
    37 publicfunction operation()
    38 {
    39 $this->_implementor->operation();
    40 }
    41 }
    42
    43 class RefinedAbstraction extends Abstraction
    44 {
    45 }
    46
    47 class ExampleAbstraction extends Abstraction
    48 {
    49 }
    50
    51 //
    52 $objRAbstraction=new RefinedAbstraction();
    53 $objRAbstraction->setImplementor(new ConcreteImplementorB());
    54 $objRAbstraction->operation();
    55
    56 $objRAbstraction->setImplementor(new ConcreteImplementorA());
    57 $objRAbstraction->operation();
    58
    59 $objEAbstraction=new ExampleAbstraction();
    60 $objEAbstraction->setImplementor(new ConcreteImplementorB());
    61 $objEAbstraction->operation();
  • 相关阅读:
    idea 编程字体推荐
    推荐!国外程序员整理的系统管理员资源大全
    jquery阻止事件冒泡的3种方式
    web前端打印总结
    前端打印插件
    object实现小老鼠交互
    前端性能优化(DOM篇)
    输入框获得焦点时外边框颜色改变
    webstorm配置scss自动编译路径
    微信开发测试号配置
  • 原文地址:https://www.cnblogs.com/bluefrog/p/2086439.html
Copyright © 2011-2022 走看看