Ejemplo n.º 1
0
        private static void ShowDecorator()
        {
            Console.WriteLine("================================================");
            Console.WriteLine("Pattern code (Decorator):");
            ConcreteComponent  c  = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();

            d1.SetComponent(c);
            d2.SetComponent(d1);

            d2.Operation();

            Console.WriteLine("\nReal code (Decorator):");

            Pizza pizza1 = new ItalianPizza();

            pizza1 = new TomatoPizza(pizza1); // итальянская пицца с томатами
            Console.WriteLine("Название: {0}", pizza1.Name);
            Console.WriteLine("Цена: {0}", pizza1.GetCost());

            Pizza pizza2 = new ItalianPizza();

            pizza2 = new CheesePizza(pizza2);// итальянская пиццы с сыром
            Console.WriteLine("Название: {0}", pizza2.Name);
            Console.WriteLine("Цена: {0}", pizza2.GetCost());

            Pizza pizza3 = new BulgerianPizza();

            pizza3 = new TomatoPizza(pizza3);
            pizza3 = new CheesePizza(pizza3);// болгарская пиццы с томатами и сыром
            Console.WriteLine("Название: {0}", pizza3.Name);
            Console.WriteLine("Цена: {0}", pizza3.GetCost());
        }
Ejemplo n.º 2
0
        static void DecoratorTester()
        {
            #region sample 1
            var c  = new ConcreteComponent();
            var d1 = new ConcreteDecoratorA();
            var d2 = new ConcreteDecoratorB();

            // Link decorators
            d1.SetComponent(c);
            d2.SetComponent(d1);

            d2.Operation();

            #endregion


            #region sample 2
            var book = new Book("Worley", "Inside ASP.NET", 10);
            book.Display();

            // Create video
            var video = new Video("Spielberg", "Jaws", 23, 92);
            video.Display();

            // Make video borrowable, then borrow and display
            Console.WriteLine("\nMaking video borrowable:");

            var borrowvideo = new Borrowable(video);
            borrowvideo.BorrowItem("Customer #1");
            borrowvideo.BorrowItem("Customer #2");

            borrowvideo.Display();
            #endregion
        }
Ejemplo n.º 3
0
    public static void Main(string[] args)
    {
        ConcreteComponent  c  = new ConcreteComponent();
        ConcreteDecoratorA d1 = new ConcreteDecoratorA();
        ConcreteDecoratorB d2 = new ConcreteDecoratorB();

        d1.SetComponent(c);
        d2.SetComponent(d1);
        d2.Operation();
    }
Ejemplo n.º 4
0
        public static void TestConcreteDecorators()
        {
            var c  = new ConcreteComponent();
            var d1 = new ConcreteDecoratorA();
            var d2 = new ConcreteDecoratorB();

            d1.SetComponent(c);
            d2.SetComponent(d1);

            StringAssert.AreEqualIgnoringCase(d2.Operation(true), "ConcreteDecoratorB.Operation()ConcreteDecoratorA.Operation()ConcreteComponent.Operation()");
        }
Ejemplo n.º 5
0
        public static void DecoratorPattern()
        {
            ConcreteComponent  c  = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();

            d1.SetComponent(c);
            d2.SetComponent(d1);
            d2.Operation();
            Console.Read();
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            ConcreteComponent  component = new ConcreteComponent();
            ConcreteDecoratorA da        = new ConcreteDecoratorA();
            ConcreteDecoratorB db        = new ConcreteDecoratorB();

            da.SetComponent(component);
            db.SetComponent(da);
            db.Operation();

            Console.ReadKey(true);
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            ConcreteComponent TextView = new ConcreteComponent();
            ConcreteDecoratorA ScrollDecorator = new ConcreteDecoratorA();
            ConcreteDecoratorB BorderDecorator = new ConcreteDecoratorB();

            ScrollDecorator.SetComponent(TextView);
            BorderDecorator.SetComponent(ScrollDecorator);
            BorderDecorator.Operation();

            Console.ReadLine();
        }
Ejemplo n.º 8
0
        public void TestDecorator()
        {
            ConcreteComponent  c  = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();

            // Link decorators
            d1.SetComponent(c);
            d2.SetComponent(d1);

            d2.Operation();
        }
Ejemplo n.º 9
0
        public static void DecoratorStructural()
        {
            // Create ConcreteComponent and two Decorators
            ConcreteComponent  c  = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();

            // Link decorators
            d1.SetComponent(c);
            d2.SetComponent(d1);

            d2.Operation();
        }
            static void Main()
            {
                // Create ConcreteComponent and two Decorators
                ConcreteComponent  c  = new ConcreteComponent();
                ConcreteDecoratorA d1 = new ConcreteDecoratorA();
                ConcreteDecoratorB d2 = new ConcreteDecoratorB();

                // Link decorators
                d1.SetComponent(c);
                d2.SetComponent(d1);
                d2.Operation();
                Console.ReadKey();
            }
        static void Main()
        {
            {
                ConcreteComponent c = new ConcreteComponent();
                ConcreteDecoratorA d1 = new ConcreteDecoratorA();
                ConcreteDecoratorB d2 = new ConcreteDecoratorB();

                d1.SetComponent(c);
                d2.SetComponent(d1);

                d2.Operation();
            }
        }
Ejemplo n.º 12
0
            private static void Test()
            {
                var c  = new ConcreteComponent();
                var d1 = new ConcreteDecoratorA();
                var d2 = new ConcreteDecoratorB();

                //Tutaj widac dekoracje
                d1.SetComponent(c);
                d2.SetComponent(d1);

                d2.Operation();

                Console.ReadKey();
            }
Ejemplo n.º 13
0
        private static void Test1()
        {
            // 首先实例化具体对象ConcreateComponent 【具体组合】
            ConcreateComponent c = new ConcreateComponent();

            // 然后实例化具体装饰类
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();

            // 开始包装
            d1.SetComponent(c);
            d2.SetComponent(d1);
            d2.Operation();
        }
Ejemplo n.º 14
0
        public Client()
        {
            ConcreteComponent concreteComponent = new ConcreteComponent();

            ConcreteDecoratorA concreteDecoratorA = new ConcreteDecoratorA();
            ConcreteDecoratorB concreteDecoratorB = new ConcreteDecoratorB();


            concreteDecoratorA.SetComponent(concreteComponent);
            concreteDecoratorB.SetComponent(concreteDecoratorA);
            concreteDecoratorB.Operation();

            Console.Read();
        }
Ejemplo n.º 15
0
        static void Run()
        {
            //实例化实现类
            ConcreteComponent concrete = new ConcreteComponent();
            //实例化装饰类
            ConcreteDecoratorA decoratorA = new ConcreteDecoratorA();
            ConcreteDecoratorB decoratorB = new ConcreteDecoratorB();

            //用装饰类装饰实现类
            decoratorA.SetComponent(concrete);
            decoratorB.SetComponent(decoratorA);

            //
            decoratorB.Operation();
        }
Ejemplo n.º 16
0
        // "Component"
        public void TestDecoratorPattern()
        {
            // Create ConcreteComponent and two Decorators
            var c  = new ConcreteComponent();
            var d1 = new ConcreteDecoratorA();
            var d2 = new ConcreteDecoratorB();

            // Link decorators
            d1.SetComponent(c);
            d2.SetComponent(d1);

            d2.Operation();

            // Wait for user
            Console.Read();
        }
Ejemplo n.º 17
0
        //Декоратор або Wrapper / Обгортка (Decorator)
        public Run Decorator()
        {
            Console.WriteLine("\nDecorator:");

            // Create ConcreteComponent and two Decorators
            ConcreteComponent  c  = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();

            // Link decorators
            d1.SetComponent(c);
            d2.SetComponent(d1);

            d2.Operation();

            return(this);
        }
Ejemplo n.º 18
0
        public void Test_Abstract_Based_Decorator()
        {
            // Create ConcreteComponent and two Decorators

            ConcreteComponent  c  = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();
            ConcreteDecoratorC d3 = new ConcreteDecoratorC();

            // Link decorators

            d1.SetComponent(c);
            d2.SetComponent(d1);
            d3.SetComponent(d2);

            d3.Operation();

            /* Ouput:
             *
             * ConcreteComponent.Operation()
             * ConcreteDecoratorA.Operation()
             * ConcreteDecoratorB.Operation()
             */
        }
Ejemplo n.º 19
0
    static void Main()
    {
        // Create ConcreteComponent and two Decorators
          ConcreteComponent c = new ConcreteComponent();
          ConcreteDecoratorA d1 = new ConcreteDecoratorA();
          ConcreteDecoratorB d2 = new ConcreteDecoratorB();

          // Link decorators
          d1.SetComponent(c);
          d2.SetComponent(d1);

          d2.Operation();

          // Wait for user
          Console.Read();
    }
Ejemplo n.º 20
0
  public static void Main( string[] args )
  {
    // Create ConcreteComponent and two Decorators
    ConcreteComponent c = new ConcreteComponent();
    ConcreteDecoratorA d1 = new ConcreteDecoratorA();
    ConcreteDecoratorB d2 = new ConcreteDecoratorB();

    // Link decorators
    d1.SetComponent( c );
    d2.SetComponent( d1 );

    d2.Operation();

  }