コード例 #1
0
        static void Main(string[] args)
        {
            ConcreteComponent  c  = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA(c);
            ConcreteDecoratorB d2 = new ConcreteDecoratorB(d1);

            d2.Operation();

            Console.ReadLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: rager520/DesignPattern
        static void RunDecorator()
        {
            // 装饰更在于给产品赋予额外的行为
            ConcreteComponent  c  = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();

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

            d2.Operation();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            #region Chain Of Responsibility
            Teamleader teamleader = new Teamleader();
            Manager    manager    = new Manager();
            SrManager  srManager  = new SrManager();

            teamleader.SetSupervisor(manager);
            manager.SetSupervisor(srManager);

            var absenceRequests = new int[] { 5, 10, 15, 20 };

            foreach (var absenceRequest in absenceRequests)
            {
                teamleader.HandleRequest(absenceRequest);
            }

            Console.Read();
            #endregion

            #region Strategy
            StrategyContext strategyContextA = new StrategyContext(new StrategyA());
            strategyContextA.RunArithmetic();

            StrategyContext strategyContextB = new StrategyContext(new StrategyB());
            strategyContextB.RunArithmetic();

            Console.Read();
            #endregion

            #region Decorator
            ConcreteComponent  concreteComponent  = new ConcreteComponent();
            ConcreteDecoratorA concreteDecoratorA = new ConcreteDecoratorA();
            ConcreteDecoratorB concreteDecoratorB = new ConcreteDecoratorB();

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

            Console.Read();
            #endregion

            #region Proxy
            Proxy.Proxy proxy = new Proxy.Proxy();
            proxy.request();

            Console.Read();
            #endregion
        }