コード例 #1
0
        static void Main(string[] args)
        {
            PurchaseRequest requestTelphone  = new PurchaseRequest(4000.0, "Telphone");
            PurchaseRequest requestSoftware  = new PurchaseRequest(10000.0, "Visual Studio");
            PurchaseRequest requestComputers = new PurchaseRequest(40000.0, "Computers");

            Approver manager = new Manager("Learning Hard");
            Approver Vp      = new VicePresident("Tony");
            Approver Pre     = new President("BossTom");

            //设置责任链
            manager.NextApprover = Vp;
            Vp.NextApprover      = Pre;

            //处理请求
            manager.ProcessRequest(requestTelphone);
            manager.ProcessRequest(requestSoftware);
            manager.ProcessRequest(requestComputers);

            Console.ReadLine();
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            Approver director = new Director();
            Approver vicePrez = new VicePresident();
            Approver prez     = new President();

            director.SetSuccessor(vicePrez);
            vicePrez.SetSuccessor(prez);

            Purchase asset1 = new Purchase(2500, 300, "Short-term supplies");

            director.ProcessRequest(asset1);

            Purchase asset2 = new Purchase(2491, 50000, "Long-term supplies");

            director.ProcessRequest(asset2);

            Purchase asset3 = new Purchase(2811, 200000, "Short-term supplies");

            director.ProcessRequest(asset3);

            Console.ReadKey();
        }