Applied Design Patterns with Java

Behavioral :: Chain of Responsibility (223) {C ch 16}


Collaborations

Consequences

Chain of Responsibility has the following benefits and liabilities:

  1. Reduced coupling. The pattern frees an object from knowing which other object handles a request. An object only has to know that a request will be handled "appropriately." Both the receiver and the sender have no explicit knowledge of each other, and an object in the chain doesn't have to know about the chain's structure. As a result, Chain of Responsibility can simplify object interconnections. Instead of objects maintaining references to all candidate receivers, they keep a single reference to their successor.
  2. Added flexibility in assigning responsibilities to objects. Chain of Responsibility gives added flexibility in distributing responsibilities among objects. It is easy to add or change responsibilities for handling a request by adding to or otherwise changing the chain at run-time; this can be combined with subclassing to specialize handlers statically.
  3. Receipt isn't guaranteed. Since a request has no explicit receiver, there's no guarantee it'll be handled—the request can fall off the end of the chain without ever being handled. A request can also go unhandled when the chain is not configured properly.

Catalog Behavioral Prev Next