Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chain of Responsibility

Similar presentations


Presentation on theme: "Chain of Responsibility"— Presentation transcript:

1 Chain of Responsibility

2 A Day in IT-support Front-line Support Second-line Support
Internal support IT Issue (= easy) IT Issue (= hard) IT Issue (= very hard) Hmmmm… IT Issue (> hard) IT Issue (> very hard) IT Issue (> easy) IT Issue Front-line Support Manager Second-line Support Manager Internal Support Manager On-site Supporter DCS – SWC

3 A Day in IT-support Even though the involved managers are different, they essentially handle issues the same way: Can my department handle the issue? If yes, pass it to an actual handler in my department, and fix the issue If no, pass it to the next department manager DCS – SWC

4 Chain of Responsibility
In more abstract terms: We have a chain of Handlers available Each handler can handle a Request A Request is handled the same way by all Handlers: Can I handle the Request? If yes, then process it (and thereby consume it) If no, pass it on to the next handler DCS – SWC

5 Chain of Responsibility
Handler handleRequest(Request r) ConcreteHandlerA handleRequest(Request r) ConcreteHandlerB handleRequest(Request r) DCS – SWC

6 Chain of Responsibility
public void handleRequest(Request r) { if (canHandleRequest(r)) processRequest(r) else forwardRequest(r); } DCS – SWC

7 Chain of Responsibility
public void forwardRequest(Request r) { if (successor != null) successor.handleRequest(r) else throw (new UnhandledRequestException()); } DCS – SWC

8 Chain of Responsibility
Notice that a Handler has a reference to Handler – the successor in the chain of Handler objects One Handler does not know about details of other handlers Order of handlers can be changed dyna-mically, since handlers do not depend on each other DCS – SWC

9 Chain of Responsibility
Issues to consider in practice Can we be sure all requests are handled? What happens if a request is not handled by the final handler? Should the behavior of a handler depend on whether or not it has a successor? Who manages the chain of handlers during run-time? DCS – SWC

10 Chain of Responsibility
Issues to consider in practice How does a Handler actually decide, if it can handle a specific request Is it acceptable if two handlers can handle the same request? What if a request should return some value? DCS – SWC


Download ppt "Chain of Responsibility"

Similar presentations


Ads by Google