C# 责任链模式
/* * 责任链模式 * abstract 抽象类 抽象方法 不能被实例化,被继承类必须实现抽象方法 * */ public abstract class Response { protected Response NextResponse; public abstract void Handle(int dayNum); } public class Director : Response { public Director() { NextResponse = new TopManage(); } public override void Handle(int dayNum) { Console.WriteLine("主管审批同意"); if (dayNum > 3) { NextResponse.Handle(dayNum); } } } public class TopManage : Response { public TopManage() { NextResponse = new Chief(); } public override void Handle(int dayNum) { Console.WriteLine("经理审批同意"); if (dayNum > 7) { NextResponse.Handle(dayNum); } } } public class Chief : Response { public override void Handle(int dayNum) { Console.WriteLine("总监审批同意"); } } //调用 Response direct = new Director(); direct.Handle(9);