Chapter 16. Chain of Responsibility Pattern

The Chain of Responsibility pattern allows a number of classes to attempt to handle a request, without any of them knowing about the capabilities of the other classes. It provides a loose coupling between these classes; the only common link is the request that is passed between them. The request is passed along until one of the classes can handle it.

One example of such a pattern is a Help system like the one shown in Figure 16.1. Here, every screen region of an application invites you to seek help, but in some window background areas, more generic help is the only suitable result.

A simple application where different screen areas provide different help messages.

Figure 16.1. A simple ...

Get Java™ Design Patterns: A Tutorial 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.