コード例 #1
0
        static void Main()
        {
            // Create ConcreteComponent and two Decorators
            ConcreteComponent  c  = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();

            ChristmasTree ct = new ChristmasTree();

            ToyChristmasTreeDecorator     td = new ToyChristmasTreeDecorator();
            GarlandChristmasTreeDecorator gd = new GarlandChristmasTreeDecorator();

            td.SetTree(ct);
            gd.SetTree(ct);
            td.DecotateChristmasTree();
            gd.DecotateChristmasTree();
            // Link decorators
            d1.SetComponent(c);
            d2.SetComponent(d1);

            d2.Operation();

            // Wait for user
            Console.Read();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ksush23/Patterns
        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();
        }