static void Main() { HandlerBase handlerA = new ConcreteHandlerA(); HandlerBase handlerB = new ConcreteHandlerB(); handlerA.SetSuccessor(handlerB); handlerA.HandleRequest(1); handlerB.HandleRequest(11); }
static void Main(string[] args) { Handler handlerA = new ConcreteHandlerA(); Handler handlerB = new ConcreteHandlerB(); Handler handlerC = new ConcreteHandlerC(); handlerA.Successor = handlerB; handlerB.Successor = handlerC; handlerA.HandleRequest(); Console.ReadLine(); }
private static void Main() { var concreteHandlerA = new ConcreteHandlerA(); var concreteHandlerB = new ConcreteHandlerB(); var concreteHandlerC = new ConcreteHandlerC(); concreteHandlerA.SetSuccessor(concreteHandlerB); concreteHandlerB.SetSuccessor(concreteHandlerC); concreteHandlerA.HandleRequest("Request"); Console.ReadKey(); }
private static void Main() { var concreteHandlerA = new ConcreteHandlerA(); var concreteHandlerB = new ConcreteHandlerB(); var concreteHandlerC = new ConcreteHandlerC(); concreteHandlerA.SetSuccessor(concreteHandlerB); concreteHandlerB.SetSuccessor(concreteHandlerC); int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 }; foreach (var request in requests) { concreteHandlerA.HandleRequest(request); } Console.ReadKey(); }
static void Main(string[] args) { Handler h1 = new ConcreteHandlerA(); Handler h2 = new ConcreteHandlerB(); Handler h3 = new ConcreteHandlerC(); h1.SetSuccessor(h2); h2.SetSuccessor(h3); int[] requests = { 1, 5, 7, 19, 40, 23, 2, 10, 0 }; foreach (var request in requests) { h1.HandleRequest(request); } Console.ReadKey(); }
static void Main(string[] args) { //实例化请求处理对象 Handler h1 = new ConcreteHandlerA(); Handler h2 = new ConcreteHandlerB(); Handler h3 = new ConcreteHandlerC(); //设置职责链的上下级关系 h1.SetSuccessor(h2); h2.SetSuccessor(h3); int[] request = new int[] { 1, 3, 10, 16, 20, 22, 29, 31 }; //传递不同请求值给请求处理者 foreach (var req in request) { h1.RequestHandler(req); } Console.Read(); }