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

    桥接模式:将对象部分与它的实现部分分离,使它们可以独立的变化。

    结构图:

     

        class Abstraction
        {
            protected Implementor implementor;

            public void SetImplementor(Implementor implementor)
            {
                this.implementor = implementor;
            }

            public virtual void Operation()
            {
                implementor.Operation();
            }
        }

        class RefinedAbstraction : Abstraction
        {
            public override void Operation()
            {
                implementor.Operation();
            }
        }
     
        abstract class Implementor
        {
            public abstract void Operation();
        }
        class ConcreteImplementorA : Implementor
        {
            public override void Operation()
            {
                //throw new NotImplementedException();
                Console.WriteLine("具体实现A的方法执行");
            }
        }
     
        class ConcreteImplementorB : Implementor
        {
            public override void Operation()
            {
                //throw new NotImplementedException();
                Console.WriteLine("具体实现B的方法执行");
            }
        }
        class Program
        {
            static void Main(string[] args)
            {
                Abstraction ab = new RefinedAbstraction();

                ab.SetImplementor(new ConcreteImplementorA());
                ab.Operation();

                ab.SetImplementor(new ConcreteImplementorB());
                ab.Operation();

                Console.ReadKey();
            }
        }
  • 相关阅读:
    Jmeter beanshell preprocessor随机添加任意多个请求参数
    Jmeter 场景设计
    jmeter 参数化
    .net 匿名方法
    jmeter 运行脚本报错 java.net.BindException: Address already in use
    Jmeter mysql性能测试
    ngcordova 监控网络制式改变
    建立apk定时自动打包系统第一篇——Ant多渠道打包并指定打包目录和打包日期
    Kafka架构
    Linux命令
  • 原文地址:https://www.cnblogs.com/lmfeng/p/2621111.html
Copyright © 2011-2022 走看看