Пример #1
0
        static void Main(string[] args)
        {
            Approver larry = new Director();
            Approver sam   = new VicePresident();
            Approver tammy = new President();

            larry.SetSuccessor(sam);
            sam.SetSuccessor(tammy);

            Purchase p = new Purchase(2034, 350.00, "Assets");

            larry.ProcessRequest(p);

            p = new Purchase(2035, 32590.10, "Project X");
            larry.ProcessRequest(p);

            p = new Purchase(2036, 122100.00, "Project Y");
            larry.ProcessRequest(p);

            Console.ReadKey();
        }
Пример #2
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("LearningHard");
            Approver Vp      = new VicePresident("Tony");
            Approver Pre     = new President("BossTom");

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

            // 处理请求
            Console.WriteLine("\n\nRequest For : Telphone");
            manager.ProcessRequest(requestTelphone);
            Console.WriteLine("\n\nRequest For : Visual Studio");
            manager.ProcessRequest(requestSoftware);
            Console.WriteLine("\n\nRequest For : Computers");
            manager.ProcessRequest(requestComputers);
            Console.ReadLine();
        }