class1.cs

来自「来自DoFactory的设计模式, 由于是本人根据已有代码创建,没有NETOpt」· CS 代码 · 共 83 行

CS
83
字号
// Bridge pattern -- Structural example  

using System;

namespace DoFactory.GangOfFour.Bridge.Structural
{

    // MainApp test application 

    class MainApp
    {
        static void Main()
        {
            Abstraction ab = new RefinedAbstraction();

            // Set implementation and call 
            ab.Implementor = new ConcreteImplementorA();
            ab.Operation();

            // Change implemention and call 
            ab.Implementor = new ConcreteImplementorB();
            ab.Operation();

            // Wait for user 
            Console.Read();
        }
    }

    // "Abstraction" 

    class Abstraction
    {
        protected Implementor implementor;

        // Property 
        public Implementor Implementor
        {
            set { implementor = value; }
        }

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

    // "Implementor" 

    abstract class Implementor
    {
        public abstract void Operation();
    }

    // "RefinedAbstraction" 

    class RefinedAbstraction : Abstraction
    {
        public override void Operation()
        {
            implementor.Operation();
        }
    }

    // "ConcreteImplementorA" 

    class ConcreteImplementorA : Implementor
    {
        public override void Operation()
        {
            Console.WriteLine("ConcreteImplementorA Operation");
        }
    }

    // "ConcreteImplementorB" 

    class ConcreteImplementorB : Implementor
    {
        public override void Operation()
        {
            Console.WriteLine("ConcreteImplementorB Operation");
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?