static void Main() { //this code comes last after the blueprint for the chain is set up below. //define some Approvers: Approver lucy = new Director(); Approver ricky = new VicePresident(); Approver ginger = new President(); //assign each of their successors (except Pres, who is the end of the chain): lucy.SetSuccessor(ricky); ricky.SetSuccessor(ginger); //generate a purchase request: Purchase p1 = new Purchase(888, 350.00, "Assets"); //then send it to the first link in the approval chain: lucy.ProcessRequest(p1); //approved by director //repeat with other amounts: Purchase p2 = new Purchase(889, 40000.00, "Vehicle"); lucy.ProcessRequest(p2); //approved by president Purchase p3 = new Purchase(890, 140000.00, "Office Annex"); lucy.ProcessRequest(p3); //not approved; meeting scheduled. //wait for user: Console.ReadKey(); }
static void Main() { // Setup Chain of Responsibility Approver ronny = new Director(); Approver bobby = new VicePresident(); Approver ricky = new President(); ronny.SetSuccessor(bobby); bobby.SetSuccessor(ricky); // Generate and process purchase requests Purchase p = new Purchase(8884, 350.00, "Assets"); ronny.ProcessRequest(p); p = new Purchase(5675, 33390.10, "Project Poison"); ronny.ProcessRequest(p); p = new Purchase(5676, 144400.00, "Project BBD"); ronny.ProcessRequest(p); // Wait for user Console.ReadKey(); }