Beispiel #1
0
        static bool TestBridgePattern()
        {
            Console.WriteLine("TESTING THE BRIDGE DESIGN PATTERN: ");

            Abstraction abstraction = new DerivedAbstraction();

            abstraction.Implementor = new ConcreteImplementorA();
            abstraction.Operation();
            //Outputs "Method called from ConcreteImplementorA"

            abstraction.Implementor = new ConcreteImplementorB();
            abstraction.Operation();
            //Outputs "Method called from ConcreteImplementorB"

            return(true);
        }
Beispiel #2
0
        private static void StructuralPaterns()
        {
            #region Example of Adapter patern
            Console.WriteLine("Adaptor Pattern");
            ITarget t = new SomeTarget();
            t.Request();

            ITarget t2 = new Adapter();
            t2.Request();

            #endregion

            #region Bridge

            Console.WriteLine("Bridge");
            Abstraction abstraction = new DerivedAbstraction();
            abstraction.Implementor = new ConcretImplementorA();
            abstraction.Operation();

            abstraction.Implementor = new ConcretImplementorB();
            abstraction.Operation();
            #endregion

            #region Facade
            Console.WriteLine("Facade");
            Facade facade = new Facade();
            facade.CallOperaionsUnified();

            #endregion

            #region Decorator
            ConcretComponent  component  = new ConcretComponent();
            ConcretDecoratorA decoratorA = new ConcretDecoratorA(component);
            ConcretDecoratorB decoratorB = new ConcretDecoratorB(decoratorA);

            component.Operation();

            decoratorA.Operation();

            decoratorB.Operation();
            #endregion
        }