Exemple #1
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
        }
Exemple #2
0
        static void Main(string[] args)
        {
#if DECORATOR
            Person ms = new Person("MarsonShine");
            Console.WriteLine("\n 第一种妆扮:");
            TShirts    dtx = new TShirts();
            BigTrouser bt  = new BigTrouser();
            dtx.Decorate(ms);
            bt.Decorate(dtx);
            bt.Show();
#endif
#if Proxy
            SchoolGirl zhuqin = new SchoolGirl();
            zhuqin.Name = "祝琴";
            Proxy.Proxy ms = new Proxy.Proxy(zhuqin);
            ms.GiveChocolate();
            ms.GiveDolls();
            ms.GiveFlowers();
            Console.ReadLine();
#endif

#if ChanOfResposibility
            HandsetBrand hb;
            hb = new HandsetBrandN();
            hb.SetHandsetSoft(new HandsetGame());
            hb.Run();

            hb.SetHandsetSoft(new HandsetAddressList());
            hb.Run();

            HandsetBrand hb2;
            hb2 = new HandsetBrandM();
            hb2.SetHandsetSoft(new HandsetGame());
            hb2.Run();

            hb2.SetHandsetSoft(new HandsetAddressList());
            hb2.Run();
#endif
#if ChainOfResiposibility
            CommonManager  jinli       = new CommonManager("jinli");
            Majordomo      zongjian    = new Majordomo("zongjian");
            GeneralManager zhongjingli = new GeneralManager("zhongjinli");
            jinli.SetSuperior(jinli);
            zongjian.SetSuperior(zhongjingli);

            Request request = new Request();
            request.RequestType    = "请假";
            request.RequestContent = "我要请假";
            request.Number         = 1;
            jinli.RequestApplications(request);

            Request request2 = new Request();
            request2.RequestType    = "请假";
            request2.RequestContent = "我要请假";
            request.Number          = 4;
            jinli.RequestApplications(request2);

            Request request3 = new Request();
            request3.RequestType    = "请假";
            request3.RequestContent = "我还是要请假";
            request.Number          = 500;
            jinli.RequestApplications(request3);
#endif
            ObjectStructure o = new ObjectStructure();
            o.Attach(new Man());
            o.Attach(new Woman());

            Success v1 = new Success();
            o.Display(v1);

            Failing v2 = new Failing();
            o.Display(v2);
        }