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();
            }
        }
  • 相关阅读:
    EF的四种开发模式
    EF4.0、4.3创建表达式树状动态查询总结
    使用vs2010复制粘贴代码时特别卡用一段时间就特别卡重启也没用
    vs2012运行项目提示无法连接 asp.net development server的解决方案
    泛组件技术
    intellij idea 编译 kafka 源码
    mycat 入门使用例子
    单机器搭建 zk 集群
    redis 版的 hello world
    zk observer 节点
  • 原文地址:https://www.cnblogs.com/lmfeng/p/2621111.html
Copyright © 2011-2022 走看看