Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            var a = new ConcreteHandler1();
            var b = new ConcreteHandler2();

            a.NextHandler = b;
            Console.WriteLine(a.HandleRequest());
        }
        /// <summary>
        /// The test third.
        /// </summary>
        private static void TestThird()
        {
            // Setup Chain of Responsibility
            AbstractHandler h1 = new ConcreteHandler1();
            AbstractHandler h2 = new ConcreteHandler2();
            AbstractHandler 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();
        }