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

    • 桥接模式 将抽象部分与它的实现部分分离,使它们都可以独立地变化。
    abstract class Implementor {
        public abstract void Operation();
    }
    
    • ConcreteImplementorA 和 ConcreteImplementorB等派生类
    class ConcreteImplementorA : Implementor {
        public override void Operation() {
            Console.WriteLine("具体实现A的方法执行");
        }
    }
    
    class ConcreteImplementorB : Implementor {
        public override void Operation() {
            Console.WriteLine("具体实现B的方法执行");
        }
    }
    
    • Abstraction类
    class Abstraction {
        protected Implementor implementor;
        
        public void SetImplementor (Implementor implementor) {
            this.implementor = implementor;
        }
        
        public virtual void Operation() {
            implementor.Operation();
        }
    }
    
    • RefinedAbstraction类
    class RefinedAbstraction : Abstraction {
        public override void Operation() {
            implementor.Operation();
        }
    }
    
    • 客户端实现
    static void Main (String[] args) {
        Abstraction ab = new RefinedAbstraction();
        
        ab.SetImplementor(new ConcreteImplementorA());
        ab.Operation();
        
        ab.SetImplementor(new ConcreteImplementorB());
        ab.Operation();
        
        Console.Read();
    }
    
  • 相关阅读:
    git 拉取开发代码
    android webview
    H5 元素定位
    Python中模块
    服务器1
    活动
    宝塔面板-阿里部署
    最新版Xshell、Xftp注册机NetSarang
    最新版Navicat Premium激活,附激活工具
    9月29更新美版T-mobile版本iPhone7代和7P有锁机卡贴解锁方法
  • 原文地址:https://www.cnblogs.com/sanjun/p/8306729.html
Copyright © 2011-2022 走看看