Пример #1
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();
    }
Пример #2
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();
        }
Пример #3
0
        public static void TestDecorator()
        {
            IComponent component = new ConcreteComponent();

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

            Console.WriteLine(decorator.Operation());
            decorator = new ConcreteDecoratorB(decorator);
            Console.WriteLine(decorator.Operation());
        }
Пример #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()");
        }
Пример #5
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();
        }
Пример #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);
        }
Пример #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();
        }
            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();
            }
Пример #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();
        }
Пример #10
0
        static void Main(string[] args)
        {
            ConcreteComponent  concreteComponent  = new ConcreteComponent();
            ConcreteDecoratorA concreteDecoratorA = new ConcreteDecoratorA();
            ConcreteDecoratorB concreteDecoratorB = new ConcreteDecoratorB();

            concreteDecoratorA.Component = concreteComponent;
            concreteDecoratorB.Component = concreteDecoratorA;

            concreteDecoratorB.Operation();

            Console.Read();
        }
        static void Main()
        {
            {
                ConcreteComponent c = new ConcreteComponent();
                ConcreteDecoratorA d1 = new ConcreteDecoratorA();
                ConcreteDecoratorB d2 = new ConcreteDecoratorB();

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

                d2.Operation();
            }
        }
Пример #12
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();
        }
Пример #13
0
        static void Main(string[] args)
        {
            Component component = new ConcreteComponent();

            Abstraction.Decorator decoratorA = new ConcreteDecoratorA();
            Abstraction.Decorator decoratorB = new ConcreteDecoratorB();

            decoratorA.Component = component;
            decoratorB.Component = decoratorA;

            decoratorB.Operation();

            Console.ReadKey();
        }
Пример #14
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();
            }
Пример #15
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();
        }
Пример #16
0
        public static void Create()
        {
            var c  = new ConcreteComponent();
            var d1 = new ConcreteDecoratorA();
            var d2 = new ConcreteDecoratorB();

            // Link decorators.
            d1.Component = c;
            d2.Component = d1;

            // Do the operation.

            d2.Operation();
        }
Пример #17
0
        static void Run()
        {
            //实例化实现类
            ConcreteComponent concrete = new ConcreteComponent();
            //实例化装饰类
            ConcreteDecoratorA decoratorA = new ConcreteDecoratorA();
            ConcreteDecoratorB decoratorB = new ConcreteDecoratorB();

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

            //
            decoratorB.Operation();
        }
Пример #18
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();
        }
Пример #19
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);
        }
Пример #20
0
        static void Main(string[] args)
        {
            Component component = new ConcreteComponent();

            //第一次修饰
            component = new ConcreteDecoratorA(component);
            //第二次装饰
            component = new ConcreteDecoratorB(component);

            component.Operation();

            //Person p = new Person("sun");
            //Shirt t  = new Shirt();
            //t.Decorate(p);
            //t.Show();
            Console.ReadLine();
        }
Пример #21
0
    public static void Main()
    {
        ConcreteComponent cc = new ConcreteComponent();

        cc.Operation();
        Console.WriteLine();

        ConcreteDecoratorA cd1 = new ConcreteDecoratorA(cc);

        cd1.Operation();
        Console.WriteLine();

        ConcreteDecoratorB cd2 = new ConcreteDecoratorB(cd1);

        cd2.Operation();
        Console.WriteLine();

        Console.ReadKey();
    }
Пример #22
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();

  }
Пример #23
0
        /// <summary>
        /// Execute decorator design pattern example
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Decorator_OnClick(object sender, RoutedEventArgs e)
        {
            var simpleComponent = new ConcreteComponent();

            DesignPatternsLog.Text += $"Decorator@ I get a simple component: {simpleComponent.Operation()}";
            DesignPatternsLog.Text += $"{Environment.NewLine}";

            // Note how decorators can wrap not only simple components
            // but the other decorators as well.
            var decoratorA = new ConcreteDecoratorA(simpleComponent);
            var decoratorB = new ConcreteDecoratorB(decoratorA);

            DesignPatternsLog.Text += $"Decorator@ Now I've got a decorated component: {decoratorB.Operation()}";
            DesignPatternsLog.Text += $"{Environment.NewLine}";
        }
Пример #24
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();
    }