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

    bridge

    使用思路:在同一个软件内保存不同版本的功能,尤其是新功能替代旧功能,但旧功能又要继续为已有客户程序服务。

    例子

    简单的桥接代码:

      using System;
     
      class BridgePattern {
        
        // Bridge Pattern                           Judith Bishop Dec 2006, Aug 2007
        // Shows an abstraction and two implementations proceeding independently
     
        class Abstraction  {
          Bridge bridge;
          public Abstraction (Bridge implementation) {
            bridge = implementation;
          }
            public string Operation () {
            return "Abstraction" +" <<< BRIDGE >>>> "+bridge.OperationImp();
          }
        }
        
        interface Bridge {
          string OperationImp();
        }
        
        class ImplementationA : Bridge {
          public string  OperationImp () {
            return "ImplementationA";
          }
        }
        
        class ImplementationB : Bridge {
          public string  OperationImp () {
            return "ImplementationB";
          }
        }
        
        static void Main () {
          Console.WriteLine("Bridge Pattern\n");
          Console.WriteLine(new Abstraction (new ImplementationA()).Operation());
          Console.WriteLine(new Abstraction (new ImplementationB()).Operation());
          Console.ReadKey();
        }
      }
    /* Output
    Bridge Pattern
    Abstraction <<< BRIDGE >>>> ImplementationA
    Abstraction <<< BRIDGE >>>> ImplementationB
    */
  • 相关阅读:
    MySQL约束笔记
    MySQL 存储过程入门
    数据库范式
    Hibernate 懒加载 错误----no session
    复选框 checkbox 选中事件
    Hibernate 三种状态变化 与 sql 语句的关系
    Spring 4 + Hibernate 4 下 getCurrentSession()的使用情况
    35个java代码性能优化总结
    为什么 Java中1000==1000为false而100==100为true?AND "2+2=5"?
    MyBatis对象关联关系----多对多的保存与查询
  • 原文地址:https://www.cnblogs.com/my36z/p/1515135.html
Copyright © 2011-2022 走看看