Summary

When you apply the CHAIN OF RESPONSIBILITY pattern, you relieve a client from having to know which object in a collection supports a given behavior. By setting up the search for responsibility to occur across objects, you decouple the client from any specific object in the chain.

The CHAIN OF RESPONSIBILITY pattern occurs occasionally when an arbitrary chain of objects can apply a series of different strategies to tackling a problem, such as parsing a user's input. More frequently this pattern occurs in aggregations, in which a containment hierarchy provides a natural ordering for a chain of objects.CHAIN OF RESPONSIBILITY leads to simpler code in both the hierarchy and the client, which is the main advantage of this pattern.

Get Design Patterns Java™ Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.