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
  • 相关阅读:
    SPOJ SAMER08A
    SPOJ TRAFFICN
    CS Academy Set Subtraction
    CS Academy Bad Triplet
    CF Round 432 C. Five Dimensional Points
    CF Round 432 B. Arpa and an exam about geometry
    SPOJ INVCNT
    CS Academy Palindromic Tree
    身体训练
    简单瞎搞题
  • 原文地址:https://www.cnblogs.com/uptothesky/p/5286226.html
Copyright © 2011-2022 走看看