Changes

Jump to: navigation, search

Chain of Responsibility

6 bytes added, 21:09, 2 April 2007
no edit summary
----
== UML Diagram ==
 
[[Image:CoR_UML.jpg]]
 
 
The role of every class:
 
*'''Handler''' - defines an interface for handling requests
*'''ConcreteHandler:'''
**handles the requests it is responsible for
**If it can handle the request it does so, otherwise it sends the request to its successor
* '''Client''' - sends commands to the first object in the chain that may handle the command
 
----
==Applicability==
* The group of objects that may handle the request must be specified in a dynamic way
 
 
----
 
== Drawbacks ==
 
* '''Unhandled requests'''
**Unfortunately, the Chain doesn't guarantee that every command is handled, which makes the problem worse, since unhandled commands propagate through the full length of the chain, slowing down the application. One way to solve this is by checking if, at the end of the chain, the request has been handled at least once, otherwise we will have to implement handlers for all the possible requests that may appear.
*'''Broken Chain'''
**Sometimes we could forget to include in the implementation of the handleRequest method the call to the successor, causing a break in the chain. The request isn’t sent forward from the broken link and so it ends up unhandled.
 
----
== UML Diagram ==
 
[[Image:CoR_UML.jpg]]
 
 
The role of every class:
 
*'''Handler''' - defines an interface for handling requests
*'''ConcreteHandler:'''
**handles the requests it is responsible for
**If it can handle the request it does so, otherwise it sends the request to its successor
* '''Client''' - sends commands to the first object in the chain that may handle the command
 
----
 
== Code Examples ==
=== Java Example ===
1
edit

Navigation menu