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 ...