Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Handler a = new HandlerA();
            Handler b = new HandlerB();
            Handler c = new HandlerC();

            a.setHandler(b);
            b.setHandler(c);

            int[] requestArr = { 2, 3, 12, 1, 25, 10 };
            foreach (var item in requestArr)
            {
                a.HandleRequest(item);
                //循环给最小处理者
            }
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // Setup Chain of Responsibility

            AbstractHandler h1 = new HandlerA();
            AbstractHandler h2 = new HandlerB();
            AbstractHandler h3 = new HandlerC();

            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();
        }