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();
            }
        }
  • 相关阅读:
    mysql操作规范
    在线修改大表结构pt-online-schema-change
    MySQL 过滤复制
    IDEA “Cannot resolve symbol” 解决办法
    JAVA NIO Selector Channel
    Mysql二级索引
    技术选型关于redis客户端选择
    知乎上看到的一篇讲解Epoll的文章,较形象生动
    linux安装运行virtuoso数据库的详细过程
    go安装步骤(linux和Windows)
  • 原文地址:https://www.cnblogs.com/lmfeng/p/2621111.html
Copyright © 2011-2022 走看看