重定义角色 修改抽象化角色中引用到实现化角色的行为。
Inheritance: Abstraction
Ejemplo n.º 1
0
        static void BridgeTester()
        {
            #region sample 1

            var ab = new RefinedAbstraction {
                Implementor = new ConcreteImplementorA()
            };
            // Set implementation and call
            ab.Operation();

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

            #region sample 2

            var customers = new Customers("Chicago")
            {
                Data = new CustomersData()
            };

            // Set ConcreteImplementor

            // Exercise the bridge
            customers.Show();
            customers.Next();
            customers.Show();
            customers.Next();
            customers.Show();
            customers.Add("Henry Velasquez");

            customers.ShowAll();
            #endregion
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 桥梁模式场景代码
        /// </summary>
        public void BridgeDemo()
        {
            IImplementor imp = new ConcreteImplementor();
            Abstraction  abs = new RefinedAbstraction(imp);

            abs.Request();
        }
Ejemplo n.º 3
0
        public static void Test()
        {
            var refinedAbstraction = new RefinedAbstraction();
            refinedAbstraction.implementor = new ConcreteImplementor();

            refinedAbstraction.Operation();
        }
        public Client()
        {
            IImplementor concreateImplementor = new ConcreateImplementor();
            Abstraction  abstraction          = new RefinedAbstraction(concreateImplementor);

            abstraction.Operation();
        }
Ejemplo n.º 5
0
    public static void Main()
    {
        Abstraction ra = new RefinedAbstraction();

        ra.Operation();

        Console.ReadKey();
    }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Abstraction abstraction = new RefinedAbstraction(new ConcreteImplementorA());

            abstraction.Operation();

            abstraction = new RefinedAbstraction(new ConcreteImplementorB());
            abstraction.Operation();
        }
Ejemplo n.º 7
0
        static void Main()
        {
            Abstraction abstraction = new RefinedAbstraction
            {
                Implementor = new ConcreteImplementorA()
            };

            abstraction.Operation();
        }
Ejemplo n.º 8
0
            static void Display()
            {
                Abstraction abstraction;

                abstraction = new RefinedAbstraction(new ConcreteImplementorA());
                abstraction.Operation();
                abstraction.Implementor = new ConcreteImplementorB();
                abstraction.Operation();
            }
Ejemplo n.º 9
0
        private static void BridgeExample()
        {
            var abstraction = new RefinedAbstraction
            {
                Implementor = new ConcreteImplementor()
            };

            abstraction.Operation();
        }
        public void Check_Bridge()
        {
            Abstraction ab = new RefinedAbstraction();

            ab.Implementor = new SP_Bridge.ConcreteImplementorA();
            ab.Operation();
            ab.Implementor = new SP_Bridge.ConcreteImplementorB();
            ab.Operation();
        }
        public void TestBridge()
        {
            IImplementation implementer = new ConcreteImplementation();

            var abstraction = new RefinedAbstraction(implementer);

            var result = abstraction.Operation();

            Assert.AreEqual(result, "Test");
        }
Ejemplo n.º 12
0
        public UseCase()
        {
            Abstraction abstraction;

            abstraction = new RefinedAbstraction(new ConcreteImplementorOne());
            abstraction.Operation();

            abstraction = new RefinedAbstraction(new ConcreteImplementorTwo());
            abstraction.Operation();
        }
Ejemplo n.º 13
0
        public void TestMethodBridge()
        {
            AbstractionBridge ab = new RefinedAbstraction();

            ab.Implementor = new ConcreteImplementorBridgeA();
            ab.Operation();

            ab.Implementor = new ConcreteImplementorBridgeB();
            ab.Operation();
        }
Ejemplo n.º 14
0
        public static void TestBridgeAbstraction()
        {
            Abstraction ab = new RefinedAbstraction();

            ab.Implementor = new ConcreteImplementorA();
            StringAssert.AreEqualIgnoringCase(ab.Operation(true), "ConcreteImplementorA Operation");

            ab.Implementor = new ConcreteImplementorB();
            StringAssert.AreEqualIgnoringCase(ab.Operation(true), "ConcreteImplementorB Operation");
        }
Ejemplo n.º 15
0
    static void Main()
    {
        Abstraction ab = new RefinedAbstraction();

        ab.SetImplementor(new ConcreteImplementorA());
        ab.Operation();
        ab.SetImplementor(new ConcreteImplementorB());
        ab.Operation();
        Console.ReadKey();
    }
Ejemplo n.º 16
0
        public static void main()
        {
            //定义一个实现化角色
            IImplementor imp = new ConcreteImplementor1();
            //定义一个抽象化角色
            Abstraction abs = new RefinedAbstraction(imp);

            //执行行文
            abs.Request();
        }
Ejemplo n.º 17
0
        public static void BridgePattern()
        {
            Abstraction ab = new RefinedAbstraction();

            ab.SetImplementor(new ConcreteImplementorA());
            ab.Operation();
            ab.SetImplementor(new ConcreteImplementorB());
            ab.Operation();

            Console.Read();
        }
Ejemplo n.º 18
0
        public void CallBridgeConcreteImplementor()
        {
            Abstraction abstraction = new RefinedAbstraction();

            // Set implementation
            abstraction.Imp = new ConcreteImplementorA();
            // Call operation
            string result = abstraction.Operation();

            Assert.AreEqual(result, "ConcreteImplementorA");
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            //구현과 추상을 분리함으로써 서브클래싱으로 확장하기 편합니다.
            //Bridge 패턴을 이용하면 구현을 확장하기에 좋고 추상을 확장하기에도 좋습니다.
            //AbstractFactory와 협력하여 복합하는 것이 좋습니다.
            var abstraction1 = new Abstraction(new ConcreteImplementorA());
            var abstraction2 = new RefinedAbstraction(new ConcreteImplementorB());

            abstraction1.Operation();
            abstraction2.Operation2();
        }
Ejemplo n.º 20
0
        public void BridgeUsage()
        {
            Abstraction a = new RefinedAbstraction(new Implementor1());
            Abstraction b = new RefinedAbstraction(new Implementor2());

            a.CallMethod1();
            a.CallMethod2();
            b.CallMethod1();
            b.CallMethod2();

            Assert.IsTrue(true);
        }
Ejemplo n.º 21
0
        public static void Create()
        {
            var ab = new RefinedAbstraction();

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

            // Replace the implementation with a different one (within the same object).
            ab.Implementor = new ConcreteImplementorB();
            ab.Operation();
        }
Ejemplo n.º 22
0
    void Start( )
    {
        Abstraction ab = new RefinedAbstraction();

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

        // Change implemention and call
        ab.Implementor = new ConcreteImplementorB();
        ab.Operation();
    }
Ejemplo n.º 23
0
        public static void BridgeStructural()
        {
            Abstraction ab = new RefinedAbstraction();

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

            // Change implemention and call
            ab.Implementor = new ConcreteImplementorB();
            ab.Operation();
        }
        public void TestOperation()
        {
            Abstraction ab = new RefinedAbstraction();

            // Set implementation and call
            ab.Implementor = new ConcreteImplementationOne();
            Assert.AreNotEqual(ab.Operation(), "asdf");

            // Change implemention and call
            ab.Implementor = new ConcreteImplementationTwo();
            Assert.AreEqual(ab.Operation(), "ConcreteImplementationTwo Operation");
        }
Ejemplo n.º 25
0
            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();
                Console.ReadKey();
            }
Ejemplo n.º 26
0
 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();
 }
Ejemplo n.º 27
0
  public static void Main( string[] args )
  {
    Abstraction abstraction = new RefinedAbstraction();

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

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

  }
Ejemplo n.º 28
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        public void Run()
        {
            var ab = new RefinedAbstraction
            {
                // Set implementation and call
                Implementor = new ConcreteImplementorA()
            };

            ab.Operation();

            // Change implemention and call
            ab.Implementor = new ConcreteImplementorB();
            ab.Operation();
        }
Ejemplo n.º 29
0
        public void TestMethod1()
        {
            Abstraction ab = new RefinedAbstraction();

            // Set implementation and call

            ab.Implementor = new ConcreteImplementorA();
            ab.Operation();

            // Change implemention and call

            ab.Implementor = new ConcreteImplementorB();
            ab.Operation();
        }
Ejemplo n.º 30
0
        // "Abstraction"
        public void TestBridgePattern()
        {
            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();
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Abstraction ab = new RefinedAbstraction();

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

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

            // Wait for user
            Console.ReadKey();
        }
Ejemplo n.º 32
0
        //Міст - Bridge
        public Run Bridge()
        {
            Console.WriteLine("\nBridge:");

            Abstraction ab = new RefinedAbstraction();

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

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

            return(this);
        }
Ejemplo n.º 33
0
        static void Main(string[] args)
        {
            //추상층
            Abstraction ab = new RefinedAbstraction();


            //구현층
            ab.Implementor = new ConcreteImplementorA();
            ab.Operation();

            ab.Implementor = new ConcreteImplementorB();
            ab.Operation();

            //Abstraction안의 Implementor를 쓰면되서 Implementor를 만들필요가 없다.
            //Abstraction를 통해서 선언만 함으로서 Implementor 사용가능하다.
            //다른 것도 선언만 함으로써 사용하고 싶다면 Abstraction안에 추가해주면됨 (추상층과 구현층이 분리되어있기 때문)
            //이것이 구현층과 추상층이 분리되어있는 패턴인 브릿지패턴
        }