Chain Of Responsibility Pattern Code Review

Use the Chain of Responsibility Pattern

Code Review

Code Walkthrough

The Program class creates an instance of the President, VicePresident and Director classes.

class Program { static void Main(string[] args) { President president = new President(); VicePresident vicePresident = new VicePresident(president); Director director = new Director(vicePresident);
Purchase p = new Purchase("PO-0001", 350.00, "Supplies"); director.ProcessRequest(p);
p = new Purchase("PO-0002", 32590.10, "Project X"); director.ProcessRequest(p);
p = new Purchase("PO-0003", 122100.00, "Project Y"); director.ProcessRequest(p);
Console.Read(); } }

On creation of the VicePresident object, the President object is passed into the constructor of the VicePresident object. In the same way, the VicePresident object is passed into the constructor of the Director class. The object passed into the respective constructor represents the next object in the chain, from the point-of-view of the object being created.