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

    桥接模式(Bridge):将抽象部分与它的实现部分分离,使它们都额可以独立地变化。

    namespace BridgeDesign
    {
        public abstract class Implementor
        {
            public abstract void Operation();
        }
        public class ConcreteImplementorA : Implementor
        {
            public override void Operation()
            {
                Console.WriteLine("具体实现A的方法执行");
            }
        }
        public class ConcreteImplementorB : Implementor
        {
            public override void Operation()
            {
                Console.WriteLine("具体实现B的方法执行");
            }
        }
        public class Abstraction
        {
            protected Implementor implementor;
            public void SetImplementor(Implementor implementor)
            {
                this.implementor = implementor;
            }
            public virtual void Operation()
            {
                implementor.Operation();
            }
        }
        public class RefinedAbstraction:Abstraction
        {
            public override void Operation()
            {
                implementor.Operation();
            }
        }
    }
    View Code

    测试代码:

                Abstraction ab = new RefinedAbstraction();
                ab.SetImplementor(new ConcreteImplementorA());
                ab.Operation();
                ab.SetImplementor(new ConcreteImplementorB());
                ab.Operation();
    View Code
  • 相关阅读:
    【CF833E】Caramel Clouds
    【LG2183】[国家集训队]礼物
    (ex)Lucas总结
    【CF527C】Glass Carving
    【CF833D】Red-Black Cobweb
    【LG4631】[APIO2018]Circle selection 选圆圈
    volatile梳理
    ThreadLocal梳理
    java线程基础梳理
    TCP/IP
  • 原文地址:https://www.cnblogs.com/uptothesky/p/5286226.html
Copyright © 2011-2022 走看看