public override bool Approve(ReImbursement reImbursement) { if (reImbursement.Amount <= UpperThreshold) { reImbursement.IsApproved = true; reImbursement.ApprovedLevel = Level; reImbursement.ApproveComment = "Approval Done."; Console.WriteLine("For ReImbursement made by: " + reImbursement.EmployeeName + ". Approved by Manager, Comment: " + reImbursement.ApproveComment); return true; } if (null != NextEscalation) { Console.WriteLine("For ReImbursement made by: " + reImbursement.EmployeeName + ". Escalated to next Level to " + NextEscalation.Level); return NextEscalation.Approve(reImbursement); } return false; }
public static void RunChainOfResponsibility() { var timCabRequest = new ReImbursement("R4322", "Tim Berners-Lee", 900.0, "Took Cab for Airport"); var itRequest = new ReImbursement("IT", "Team IT", 35000.0, "Purchased Desktop for Team"); Approver manager = new Manager("Q1234", "James Gosling"); Approver srManager = new SeniorManager("W1234", "Bill Gates"); Approver director = new Director("S1234", "Steve Jobs"); manager.SetNextEscalation(srManager); srManager.SetNextEscalation(director); manager.Approve(timCabRequest); manager.Approve(itRequest); }
public abstract bool Approve(ReImbursement reImbursement);
public override bool Approve(ReImbursement reImbursement) { if ((reImbursement.Amount >= LowerThreshold) && (reImbursement.Amount <= UpperThreshold)) { reImbursement.IsApproved = true; reImbursement.ApprovedLevel = Level; reImbursement.ApproveComment = "Approval Done."; Console.WriteLine("Approved by Director, Comment: " + reImbursement.ApproveComment); return true; } return false; }