Chain of Responsibility Pattern
Overview
Avoid coupling the sender of a request to its receiver by giving more than one
object a chance to handle the request. Chain the receiving objects and pass
the request along the chain until an object can handle it.
Participants
- defines an interface for handling requests.
- implements the successor link.
- this participant can not be read-only.
- this participant can not be an interface.
- handles requests it is responsible for.
- can access its successor.
-
if the Handler implementation can handle the request, it does so; otherwise it
forwards the requests to its successor.
Parameters
-
here you can specify the name of an attribute where the Concrete Handler will
keep a reference to its successor.
-
name of the method that should handle the request or delegate it.
-
when selected, will create special JavaDoc links in the code between pattern participants, describing
their relationships.
Applicability
Use the Chain of Responsibility when
- more than one object may handle a request, and the handler isn't known a
priori. The handler should be ascertained automatically.
-
you want to issue a request to one of several objects without specifying
the receiver explicitly.
- the set of objects that can handle a request
should be specified dynamically.