コード例 #1
0
        private static void Main()
        {
            // Customers
            var req1 = new LoanRequest {
                Customer = "John Tanta", Amount = 800
            };
            var req2 = new LoanRequest {
                Customer = "Big Dad", Amount = 1800
            };
            var req3 = new LoanRequest {
                Customer = "Cally Minou", Amount = 11800
            };

            // Approvers
            var supermanager = new SuperManager {
                Name = "Grag, super manager"
            };
            var manager = new Manager {
                Name = "Stiv, manager", Successor = supermanager
            };
            var cashier = new Cashier {
                Name = "Job, cashier", Successor = manager
            };

            // handle requests
            cashier.HandleRequest(req1);
            cashier.HandleRequest(req2);
            cashier.HandleRequest(req3);

            Console.ReadLine();
        }
コード例 #2
0
 public void HandleRequest(LoanRequest req)
 {
     if (req.Amount < 10000)
     {
         Console.WriteLine("{0}$ loan approved for {1} by {2}", req.Amount, req.Customer, Name);
     }
     else
     {
         this.TrySuccessor(req);
     }
 }
コード例 #3
0
 public static void TrySuccessor(this IRequestHandler handler, LoanRequest req)
 {
     if (handler.Successor != null)
     {
         Console.WriteLine("{0} can't approve. Pass request to {1}", handler.Name, handler.Successor.Name);
         handler.Successor.HandleRequest(req);
     }
     else
     {
         Console.WriteLine("Handler has no approval. You need some big boss");
     }
 }