public UseCase() { AbstractHandler handler1 = new ConcreteHandlerOne(); handler1.Successor = new ConcreteHandlerTwo(); handler1.HandleRequest(2); }
private static void ChainOfResponsibilityExample() { var handlerOne = new ConcreteHandlerOne(); var handlerTwo = new ConcreteHandlerTwo(); handlerOne.SetSuccessor(handlerTwo); handlerTwo.SetSuccessor(handlerOne); handlerOne.HandleRequest("PrintDate"); handlerOne.HandleRequest("PrintGreeting"); }
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); }
static void Main(string[] args) { // Setup Chain of Responsibility Handler h1 = new ConcreteHandlerOne(); Handler h2 = new ConcreteHandlerTwo(); Handler h3 = new ConcreteHandlerThree(); h1.setSuccessor(h2); h2.setSuccessor(h3); // Send requests to the chain h1.handleRequest(new Request("Negative Value", -1)); h1.handleRequest(new Request("Zero Value", 0)); h1.handleRequest(new Request("Positive Value", 1)); h1.handleRequest(new Request("Positive Value", 2)); h1.handleRequest(new Request("Negative Value", -5)); Console.ReadKey(); }
static void Main(string[] args) { // Setup Chain of Responsibility Handler h1 = new ConcreteHandlerOne(); Handler h2 = new ConcreteHandlerTwo(); Handler h3 = new ConcreteHandlerThree(); h1.setSuccessor(h2); h2.setSuccessor(h3); // Send requests to the chain h1.handleRequest(new Request("Negative Value", -1)); h1.handleRequest(new Request("Zero Value", 0)); h1.handleRequest(new Request("Positive Value", 1)); h1.handleRequest(new Request("Positive Value", 2)); h1.handleRequest(new Request("Negative Value", -5)); Console.ReadKey(); }