标签:
就是你找政府部门办事,需要层层审批,求情一层层的传递直到有权利的人通过审批为止。
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace ConsoleApplication1 { class Program { public class FetchSalary { public double Amount { get; set; } public FetchSalary(double amount) { Amount = amount; } } public abstract class Approver { public Approver Next{get;set;} public abstract void ProcessRequest(FetchSalary request); } public class PL:Approver { public override void ProcessRequest(FetchSalary request) { if (request.Amount < 100f) { Console.WriteLine("Pl approved"); } else if (Next != null) { Next.ProcessRequest(request); } } } public class PM: Approver { public override void ProcessRequest(FetchSalary request) { if (request.Amount < 1000f) { Console.WriteLine("PM approved"); } else if (Next != null) { Next.ProcessRequest(request); } } } public class Predident: Approver { public override void ProcessRequest(FetchSalary request) { if (request.Amount < 10000f) { Console.WriteLine("Predident approved"); } else if(Next != null) { Next.ProcessRequest(request); } } } static void Main(string[] args) { FetchSalary fetchSalary100 = new FetchSalary(100f); FetchSalary fetchSalary1000 = new FetchSalary(1000f); FetchSalary fetchSalary10000 = new FetchSalary(10000f); Approver pl = new PL(); Approver pm = new PM(); Approver president = new Predident(); pl.Next = pm; pm.Next = president; president.Next = null; pl.ProcessRequest(fetchSalary100); pl.ProcessRequest(fetchSalary1000); pl.ProcessRequest(fetchSalary10000); } } }
标签:
原文地址:http://www.cnblogs.com/zkzk945/p/5120848.html