The 'ConcreteComponent' class
Inheritance: Component
コード例 #1
0
ファイル: Program.cs プロジェクト: masifjaved/DesignPatterns
        static void Main()
        {
            var component = new ConcreteComponent();
            var decorator = new ConcreteDecorator(component);

            decorator.Operation();
        }
コード例 #2
0
        //https://ru.wikipedia.org/wiki/Декоратор_(шаблон_проектирования)
        //https://refactoring.guru/ru/design-patterns/decorator
        //https://metanit.com/sharp/patterns/4.1.php

        static void Main(string[] args)
        {
            // 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();

            dB.Operation();

            //OnInterface
            Implement           implement = new Implement();
            ConcreteDecoratorAI dAI       = new ConcreteDecoratorAI();
            ConcreteDecoratorBI dBI       = new ConcreteDecoratorBI();

            // Link decorators
            dAI.SetComponent(implement);
            dBI.SetComponent(dAI);

            implement.Operation();

            dAI.Operation();

            dBI.Operation();

            // Wait for user
            Console.Read();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: artag/Training
        static void Main(string[] args)
        {
            var client = new Client();

            // Клиент использует простой компонент
            var simple = new ConcreteComponent();

            Console.WriteLine("Client. ConcreteComponent:");
            client.Call(simple);
            Console.WriteLine();

            // Декораторы могут обёртывать не только
            // простые компоненты, но и другие декораторы.
            var decorator1 = new ConcreteDecoratorA(simple);

            Console.WriteLine("Client. ConcreteComponent in DecoratorA:");
            client.Call(decorator1);
            Console.WriteLine();

            var decorator2 = new ConcreteDecoratorB(decorator1);

            Console.WriteLine("Client. ConcreteComponent in Decorators A and B:");
            client.Call(decorator2);
            Console.WriteLine();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            Component      component = new ConcreteComponent();
            DecoratorClass decorator = new ConcreteDecoratorA();

            decorator.SetComponent(component);

            decorator.Operation();
        }
コード例 #5
0
        static void Main(string[] args)
        {
            Component component = new ConcreteComponent();

            component = new ConcreteDecoratorA(component);
            component = new ConcreteDecoratorB(component);

            component.Operation();
        }
コード例 #6
0
ファイル: Client.cs プロジェクト: ruslanabdraev/Patterns
        static void Main(string[] args)
        {
            Component component          = new ConcreteComponent();
            Component decoratedComponent = new ConcreteDecoratorB(new ConcreteDecoratorA(component));

            decoratedComponent.Operation();

            Console.ReadLine();
        }
コード例 #7
0
        static void Main(string[] args)
        {
            Component component = new ConcreteComponent();
            Decorator decorA    = new ConcreteDecoratorA();
            Decorator decorB    = new ConcreteDecoratorB();

            decorA.component = component;
            decorB.component = decorA;
            decorB.Operation();
        }
コード例 #8
0
        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();
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: GrigoryanArtem/Patterns
        static void Main(string[] args)
        {
            Component myComponent = new ConcreteComponent();
            Console.WriteLine("CC: {0}", myComponent.Operation());

            myComponent = new ConcreteDecoratorA(myComponent);
            Console.WriteLine("CC + DCA: {0}", myComponent.Operation());

            myComponent = new ConcreteDecoratorB(myComponent);
            Console.WriteLine("CC + DCB: {0}", myComponent.Operation());
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: Sleeeeeepy/DesignPattern
        static void Main(string[] args)
        {
            var compo      = new ConcreteComponent();
            var decorator1 = new ConcreteDecoratorA(compo);
            var decorator2 = new ConcreteDecoratorB(compo);
            var decorator3 = new ConcreteDecoratorA(new ConcreteDecoratorB(compo));

            compo.Operation();
            decorator1.Operation();
            decorator2.Operation();
            decorator3.Operation();
        }
コード例 #11
0
        private static void NewMethod2()
        {
            ConcreteComponent  c  = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();

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

            Console.Read();
        }
コード例 #12
0
        static void Main(string[] args)
        {
            ConcreteComponent conr = new ConcreteComponent();
            Component         adec = new ADecorator();
            Component         bdec = new BDecorator();

            (adec as ADecorator).SetComponent(conr);
            (bdec as BDecorator).SetComponent(adec);
            bdec.Operation();

            Console.Read();
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: suprcodr/DesignPatterns
        private static void Main()
        {
            var component          = new ConcreteComponent();
            var concreteDecoratorA = new ConcreteDecoratorA();
            var concreteDecoratorB = new ConcreteDecoratorB();

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

            Console.ReadKey();
        }
コード例 #14
0
        static void Main(string[] args)
        {
            var component = new ConcreteComponent();

            component.Operation();
            Console.WriteLine();

            var changedComponent = new DecoratedComponent(component, "new state");

            changedComponent.Operation();

            Console.ReadKey();
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: Alex-LG/DP
        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();
        }
コード例 #16
0
ファイル: Program.cs プロジェクト: duuongphilong/Demo_lab06
        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();
            // Wait for user
            Console.ReadKey();
        }
コード例 #17
0
        static void Main(string[] args)
        {
            Component obj = new ConcreteComponent();

            obj.Operation();
            Decorator objDecorator = new ConcreteDecorator();

            objDecorator.SetComponent(obj);
            objDecorator.Operation();
            Decorator objDecorator2 = new ConcreteDecorator2();

            objDecorator2.SetComponent(objDecorator);
            objDecorator2.Operation();
        }
コード例 #18
0
        static void Main()
        {
            ConcreteComponent  cmp = new ConcreteComponent();
            ConcreteDecoratorA d1  = new ConcreteDecoratorA();
            ConcreteDecoratorB d2  = new ConcreteDecoratorB();

            d1.SetComponent(cmp);
            d2.SetComponent(cmp);

            d1.Operation();
            d2.Operation();

            Console.ReadKey();
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: IharHrunt/DesignPatterns
        static void Main(string[] args)
        {
            Component component = new ConcreteComponent("Start");

            Console.WriteLine(component.Operation());

            component = new ConcreteDecoratorA(component);
            Console.WriteLine(component.Operation());

            component = new ConcreteDecoratorB(component);
            Console.WriteLine(component.Operation());

            Console.ReadLine();
        }
コード例 #20
0
        /// <summary>
        /// The test first decorator.
        /// </summary>
        private static void TestFirstDecorator()
        {
            // 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();
        }
コード例 #21
0
        static void Main(string[] args)
        {
            var client = new Client();
            var simple = new ConcreteComponent();

            System.Console.WriteLine("Client: I get a simple component");
            client.ClientCode(simple);
            System.Console.WriteLine();

            var decorator1 = new ConcreteDecoratorA(simple);
            var decorator2 = new ConcreteDecoratorB(decorator1);

            System.Console.WriteLine("Client: Now I've got a decorated component: ");
            client.ClientCode(decorator2);
        }
コード例 #22
0
        static void Main(string[] args)
        {
            Client            client          = new Client();
            ConcreteComponent simpleComponent = new ConcreteComponent();

            client.ClientCode(simpleComponent);

            ConcreteDecoratorA decoratorA = new ConcreteDecoratorA(simpleComponent);

            client.ClientCode(decoratorA);

            ConcreteDecoratorB decoratorB = new ConcreteDecoratorB(decoratorA);

            client.ClientCode(decoratorB);
        }
コード例 #23
0
ファイル: Program.cs プロジェクト: nbalage90/DesignPatterns
        static void Main(string[] args)
        {
            Console.WriteLine("***Decorator Pattern Demo***\n");
            ConcreteComponent cc = new ConcreteComponent();

            ConcreteDecoratorEx1 decorator1 = new ConcreteDecoratorEx1();

            decorator1.SetTheComponent(cc);
            decorator1.MakeHouse();

            ConcreteDecoratorEx2 decorator2 = new ConcreteDecoratorEx2();

            decorator2.SetTheComponent(decorator1);
            decorator2.MakeHouse();
        }
コード例 #24
0
        static void Main(string[] args)
        {
            Console.WriteLine("***Decorator pattern Demo***");
            ConcreteComponent     cc   = new ConcreteComponent();
            ConcreteDecoratorEx_1 cd_1 = new ConcreteDecoratorEx_1();

            cd_1.SetTheComponent(cc);
            cd_1.doJob();

            ConcreteDecoratorEx_2 cd_2 = new ConcreteDecoratorEx_2();

            cd_2.SetTheComponent(cd_1);
            cd_2.doJob();

            Console.ReadLine();
        }
コード例 #25
0
ファイル: MainApp.cs プロジェクト: mravinale/gof-patterns
        /// <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();
        }
コード例 #26
0
    { /// <summary>
      /// Entry point into console application.
      /// </summary>
        static void Main()
        {
            // 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();
        }
コード例 #27
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();
        }
コード例 #28
0
ファイル: Program.cs プロジェクト: yetisergey/Patterns
        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();
        }
コード例 #29
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());
        }
コード例 #30
0
        static void Main(string[] args)
        {
            Client client = new Client();

            var simple = new ConcreteComponent();

            Console.WriteLine("Client: I get a simple component:");
            client.ClientCode(simple);
            Console.WriteLine();

            //.. as well as decorated ones.
            //Note how decorators can wrap only simple components but the other decorators as well.
            ConcreteDecoratorA decorator1 = new ConcreteDecoratorA(simple);
            ConcreteDecoratorB decorator2 = new ConcreteDecoratorB(decorator1);

            Console.WriteLine("Client: Now I've got a decorator component:");
            client.ClientCode(decorator2);
        }
コード例 #31
0
ファイル: Program.cs プロジェクト: zhv9/StudyNotes
        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();
        }
コード例 #32
0
        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();
        }
コード例 #33
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()
             */
        }
コード例 #34
0
ファイル: Decorator.cs プロジェクト: Saroko-dnd/My_DZ
        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();
        }
コード例 #35
0
ファイル: Program.cs プロジェクト: ElvinChan/DesignPattern
        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
        }
コード例 #36
0
 static void Main()
 {
     var component = new ConcreteComponent();
     var decorator = new ConcreteDecorator(component);
     decorator.Operation();
 }
コード例 #37
0
ファイル: Program.cs プロジェクト: ehershey/development
        static void Main(string[] args)
        {
            AbstractComponent ac = new ConcreteComponent();
            AbstractComponent DecoratedAc = null;

            DecoratedAc = new Pre1Decorator(ac);
            DecoratedAc = new Pre2Decorator(DecoratedAc);
            DecoratedAc = new Post1Decorator(DecoratedAc);

            DecoratedAc.DoSomething();
            DecoratedAc.DoSomethingElse();


            DecoratedAc = new Post1Decorator(ac);
            DecoratedAc = new Pre2Decorator(DecoratedAc);
            DecoratedAc = new Pre1Decorator(DecoratedAc);

            DecoratedAc.DoSomething();
            DecoratedAc.DoSomethingElse();
        }