An example class diagram

A common example used to illustrate the chain of responsibility design pattern is about event handling in applications, depending on whether they come from a mouse or a keyboard action. For our class diagram and code example, let's take a look at something else that we use every day—ATMs. How do they return the right amount in different note combinations? The answer is, of course, the chain of responsibility.

We will present two diagrams here—one of the classes that allow us to achieve the chain of responsibility pattern and another that will show how those classes are used together to build our ATM.

First, let's take a look at our classes separately:

In the preceding diagram, we have a base class (represented as ...

Get Scala Design Patterns - Second Edition 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.