private static void Main(string[] args)
        {
            //Customers
            var request1 = new LoanRequest {
                Amount = 800, Customer = "Jimmy"
            };
            var request2 = new LoanRequest {
                Amount = 5000, Customer = "Ben"
            };
            var request3 = new LoanRequest {
                Amount = 200000, Customer = "Harry"
            };

            //Approvers, chained together
            var manager = new Manager {
                Name = "Tom, Manager"
            };
            var cashier = new Cashier {
                Name = "Job, Cachier", Successor = manager
            };

            //All customers request cashier first to approve
            cashier.HandleRequest(request1);
            cashier.HandleRequest(request2);
            cashier.HandleRequest(request3);

            Console.ReadLine();
        }
Ejemplo n.º 2
0
 public static void TrySuccessor(this IRequestHandler current, LoanRequest req)
 {
     if (current.Successor != null)
     {
         Console.WriteLine("{0} Can't approve - Passing request to {1}", current.Name, current.Successor.Name);
         current.Successor.HandleRequest(req);
     }
     else
     {
         Console.WriteLine("Amount invaid, no approval given");
     }
 }
 public void HandleRequest(LoanRequest req)
 {
     if (req.Amount < 10000)
     {
         Console.WriteLine("{0} $$ Loan approved for {1} - Approved by {2}",
                           req.Amount, req.Customer, Name);
     }
     else
     {
         this.TrySuccessor(req);
     }
 }