static void Main() { // Настраиваем цепочку Handler h1 = new ConcreteHandler1(); Handler h2 = new ConcreteHandler2(); Handler h3 = new ConcreteHandler3(); h1.SetSuccessor(h2); h2.SetSuccessor(h3); // Генерируем запросы int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 }; foreach (int request in requests) { h1.HandleRequest(request); } // Ждем нажатия пользователя Console.ReadLine(); }
static void Main() { Handler h1 = new ConcreteHandler1(); Handler h2 = new ConcreteHandler2(); h1.Successor = h2; h1.HandleRequest(1); h1.HandleRequest(2); }
static void Main(string[] args) { ConcreteHandler1 a = new ConcreteHandler1(); ConcreteHandler2 b = new ConcreteHandler2(); a.setNext(b); while (true) { Console.WriteLine("Ingresa Solicitud:"); string solicitud = Console.ReadLine(); Console.WriteLine("Ingresa Cantidad:"); int cantidad = Convert.ToInt32(Console.ReadLine()); a.handle(cantidad, solicitud); Console.ReadLine(); } }
static void Main(string[] args) { Console.WriteLine("----------职责链模式-----------"); Handler h1 = new ConcreteHandler1(); Handler h2 = new ConcreteHandler2(); Handler h3 = new ConcreteHandler3(); h1.SetOperator(h2); h2.SetOperator(h3);//设置职责链上的参与者,这里的代码可以再封装一层,因为客户端无须知道职责链上的每一个元素 int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 }; foreach (var request in requests) { h1.HandlerRequest(request);//职责链的首部来启动 } Console.Read(); }
static void Main() { // Setup Chain of Responsibility Handler h1 = new ConcreteHandler1(); Handler h2 = new ConcreteHandler2(); Handler h3 = new ConcreteHandler3(); h1.SetSuccessor(h2); h2.SetSuccessor(h3); // Generate and process request int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 }; foreach (int request in requests) { h1.HandleRequest(request); } // Wait for user Console.ReadKey(); }