Exemplo n.º 1
0
        static void Main()
        {
            ConcreteComponent c = new ConcreteComponent();
            ConcreteDecoratorA dA = new ConcreteDecoratorA();
            ConcreteDecoratorB dB = new ConcreteDecoratorB();

            dA.SetComponent(c);
            dB.SetComponent(dA);

            dB.Operation();

            Console.Read();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        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.ReadKey();
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            // 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.ReadKey();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        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.ReadKey();
        }
Exemplo n.º 5
0
        static void Main()
        {
            ConcreteComponent
                c = new ConcreteComponent();

            ConcreteDecoratorA
                d1 = new ConcreteDecoratorA();

            ConcreteDecoratorB
                d2 = new ConcreteDecoratorB();

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

            d2.Operation();
        }
Exemplo n.º 6
0
        static void Main()
        {
            ConcreteComponent  c  = new ConcreteComponent();
            ConcreteDecoratorA dA = new ConcreteDecoratorA();
            ConcreteDecoratorB dB = new ConcreteDecoratorB();

            dA.SetComponent(c);
            dB.SetComponent(dA);

            dA.Operation();

            Console.WriteLine();

            dB.Operation();

            Console.Read();
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            ConcreteComponent concreteComponent = new ConcreteComponent();

            concreteComponent.Operation();

            ConcreteDecoratorA decoratorA = new ConcreteDecoratorA();

            decoratorA.SetComponent(concreteComponent);
            ConcreteDecoratorB decoratorB = new ConcreteDecoratorB();

            decoratorB.SetComponent(concreteComponent);

            decoratorA.Operation();
            decoratorB.Operation();


            Console.WriteLine("-----------------------------");

            Repo repo = new Repo();

            repo.GetId();

            DecoratorForIRepo decoratorForIRepo = new DecoratorForIRepo(repo);

            decoratorForIRepo.GetId();

            Console.WriteLine("-----------------------------");

            new CofeeHelper().ShouldSupportCondiments();


            Console.WriteLine("-----------------------------");


            BaseCar baseCar = new BaseCar();

            Console.WriteLine(baseCar.GetCarCharacteristic());
            Console.WriteLine(baseCar.GetCost());

            ICarSet superCar = new AutomaticTransmissionSet(baseCar);

            Console.WriteLine(superCar.GetCarCharacteristic());
            Console.WriteLine(superCar.GetCost());
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            // Decorator
            ConcreteComponent  c  = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();

            // 先用ConcreteComponent实例化对象c
            // 然后用ConcreteComponentA的实例化对象d1包装c
            d1.SetComponent(c);
            // 再用ConcreteComponentB的实例化对象d2包装d1
            d2.SetComponent(d1);
            //最终执行d2的Operation()
            d2.Operation();

            Console.Read();
        }
        static void Main(string[] args)
        {
            // Se crea ConcreteComponent y 2 Decoradores

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

            // Se liga los decoradores

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

            d2.Operation();

            // Espera al usuario

            Console.ReadKey();
        }
Exemplo n.º 10
0
        public static void Run()
        {
            Console.WriteLine("This structural code demonstrates the Decorator pattern which dynamically adds extra functionality to an existing object.");

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

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

            d2.Operation();

            /*
             * ConcreteComponent.Operation()
             * ConcreteDecoratorA.Operation()
             * ConcreteDecoratorB.Operation()
             */
        }
Exemplo n.º 11
0
        static void Main()
        {
            /*
             * Structural
             */

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

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

            // Call decorators operation
            d2.Operation();

            /*
             * Real World
             */

            // Create a book
            Book book = new Book("Cantu, Jeremy", "My Life as a Person", 12345);

            book.Display();

            // Create a video
            Video video = new Video("Tarantino, Quentin", "Jeremy's Life", 54321, 60);

            video.Display();

            // Make video borrow-able, then borrow and display
            Console.WriteLine("Making video borrow-able");

            Borrowable borrowableVideo = new Borrowable(video);

            borrowableVideo.BorrowItem("Customer #1");
            borrowableVideo.BorrowItem("Customer #2");

            borrowableVideo.Display();
        }
Exemplo n.º 12
0
        static void Main()
        {
            // Create ConcreteComponent and two Decorators
            ConcreteComponent c = new ConcreteComponent();
            ConcreteDecoratorA dA = new ConcreteDecoratorA();
            ConcreteDecoratorB dB = new ConcreteDecoratorB();

            // Link decorators
            dA.SetComponent(c);
            dB.SetComponent(dA);

            dA.Operation();

            Console.WriteLine();

            dB.Operation();

            // Wait for user
            Console.Read();
        }
Exemplo n.º 13
0
        static void Main()
        {
            // Create ConcreteComponent and two Decorators
            ConcreteComponent  c  = new ConcreteComponent();
            ConcreteDecoratorA dA = new ConcreteDecoratorA();
            ConcreteDecoratorB dB = new ConcreteDecoratorB();

            // Link decorators
            dA.SetComponent(c);
            dB.SetComponent(dA);

            dA.Operation();

            Console.WriteLine();

            dB.Operation();

            // Wait for user
            Console.Read();
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            #region 基本用法(对应Basic.cs)
            ConcreteComponent c = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();

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

            d2.Operation();
            #endregion

            #region 具体实例(对应Example.cs)
            Person xc = new Person("小菜");
            Console.WriteLine("\n第一种装扮:");

            Sneaker pqx = new Sneaker();
            BigTrouser kk = new BigTrouser();
            TShirt dtx = new TShirt();

            pqx.Decorate(xc);
            kk.Decorate(pqx);
            dtx.Decorate(kk);
            dtx.Show();

            Console.WriteLine("\n第二种装扮:");

            LeatherShoes px = new LeatherShoes();
            Tie ld = new Tie();
            Suit xz = new Suit();

            px.Decorate(xc);
            ld.Decorate(px);
            xz.Decorate(ld);
            xz.Show();

            Console.ReadLine();
            #endregion
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            #region 基本用法(对应Basic.cs)
            ConcreteComponent  c  = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();

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

            d2.Operation();
            #endregion

            #region 具体实例(对应Example.cs)
            Person xc = new Person("小菜");
            Console.WriteLine("\n第一种装扮:");

            Sneaker    pqx = new Sneaker();
            BigTrouser kk  = new BigTrouser();
            TShirt     dtx = new TShirt();

            pqx.Decorate(xc);
            kk.Decorate(pqx);
            dtx.Decorate(kk);
            dtx.Show();

            Console.WriteLine("\n第二种装扮:");

            LeatherShoes px = new LeatherShoes();
            Tie          ld = new Tie();
            Suit         xz = new Suit();

            px.Decorate(xc);
            ld.Decorate(px);
            xz.Decorate(ld);
            xz.Show();

            Console.ReadLine();
            #endregion
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            #region 结构实现
            // 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();
            #endregion

            Console.WriteLine("******************************");

            #region 实践应用
            #endregion

            Console.ReadKey();
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            var c  = new ConcreteComponent();
            var d1 = new ConcreteDecoratorA();
            var d2 = new ConcreteDecoratorB();

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

            //範例
            Person xc = new Person("小菜");

            Console.WriteLine("第一種裝扮");
            var kk  = new BigTrouser();
            var dtx = new TShirts();

            kk.Decorate(xc);
            dtx.Decorate(kk);
            dtx.Show();

            Console.ReadLine();
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            Person person = new Person("小菜");

            Console.WriteLine("第一種裝扮:");
            Finery tShirts    = new TShirts();
            Finery bigTrouser = new BigTrouser();
            Finery sneakers   = new Sneakers();

            sneakers.Decorate(person);
            bigTrouser.Decorate(sneakers);
            tShirts.Decorate(bigTrouser);
            tShirts.Show();

            Console.WriteLine("\n第二種裝扮:");
            Finery suit         = new Suit();
            Finery tie          = new Tie();
            Finery leatherShoes = new LeatherShoes();

            suit.Decorate(person);
            tie.Decorate(suit);
            leatherShoes.Decorate(tie);
            leatherShoes.Show();

            Console.WriteLine("\n");

            Component component  = new ConcreteComponent();
            Decorator decoratorA = new ConcreteDecoratorA();
            Decorator decoratorB = new ConcreteDecoratorB();

            decoratorA.SetComponent(component);
            decoratorB.SetComponent(decoratorA);
            decoratorB.Operation();

            Console.ReadLine();
        }
Exemplo n.º 19
0
            static void Main()
            {
                // Конкретный компонент  и 3 Конкретных декоратора
                ConcreteComponent  c   = new ConcreteComponent();
                ConcreteDecoratorA dA  = new ConcreteDecoratorA();
                ConcreteDecoratorB dB  = new ConcreteDecoratorB();
                ConcreteDecoratorB dB2 = new ConcreteDecoratorB();

                dA.SetComponent(c);   //оборачиваем с в первый декоратор
                dB.SetComponent(c);
                dB2.SetComponent(dA); //оборачиваем dA во второй декоратор

                dA.Operation();

                Console.WriteLine();

                dB.Operation();

                Console.WriteLine();

                dB2.Operation();

                Console.Read();
            }