Ejemplo n.º 1
0
        static bool TestChainOfResponsibility()
        {
            Console.WriteLine("TESTING THE CHAIN OF RESPONSIBILITY DESIGN PATTERN: ");

            ChainHandler h1 = new ConcreteHandler("Handler 1");

            h1.Condition = (value) => value >= 0 && value < 5;

            ChainHandler h2 = new ConcreteHandler("Handler 2");

            h2.Condition = (value) => value >= 5 && value < 10;

            ChainHandler h3 = new ConcreteHandler("Handler 3");

            h3.Condition = (value) => value >= 10 && value < 15;

            h1.Successor = h2;
            h2.Successor = h3;


            foreach (var i in new int[] { 3, 4, 6, 11, 12 })
            {
                h1.HandleRequest(i);
            }

            //Output
            //Handler 1 handled the value 3
            //Handler 1 handled the value 4
            //Handler 2 handled the value 6
            //Handler 3 handled the value 11
            //Handler 3 handled the value 12

            return(true);
        }
Ejemplo n.º 2
0
        public void TestChainOfResponsability()
        {
            var handlerOne = new ConcreteHandler();
            var handlerTwo = new ConcreteHandler();

            handlerOne.SetSuccessor(handlerTwo);

            handlerOne.HandleRequest(1);
        }