Пример #1
0
        private static void ChainOfResponsibilityExample()
        {
            var handlerOne = new ConcreteHandlerOne();
            var handlerTwo = new ConcreteHandlerTwo();

            handlerOne.SetSuccessor(handlerTwo);
            handlerTwo.SetSuccessor(handlerOne);

            handlerOne.HandleRequest("PrintDate");
            handlerOne.HandleRequest("PrintGreeting");
        }
Пример #2
0
        public List <int> ProcessRequests(List <int> requestTypes)
        {
            var handlers             = new List <int>();
            var concreteHandlerOne   = new ConcreteHandlerOne();
            var concreteHandlerTwo   = new ConcreteHandlerTwo();
            var concreteHandlerThree = new ConcreteHandlerThree();

            concreteHandlerOne.SetSuccessor(concreteHandlerTwo);
            concreteHandlerTwo.SetSuccessor(concreteHandlerThree);

            foreach (var requestType in requestTypes)
            {
                handlers.Add(concreteHandlerOne.Handle(requestType));
            }

            return(handlers);
        }