
Albert Bennett
Design Patterns: Chain of Responsibility
Updated: Jul 12, 2021
Here is the link to the GitHub repo :)
Feel free to like, comment and share this post.
Scary name, I know but... what does it mean and what... does it do? In this post I'll answer those questions.
This pattern is all about passing on a request until something handles it. All without coupling the sender. Here is a diagram that explains how it all works:

For our example we want to see which of our scientists can handle a particular science request.
Client: This object is used to send the initial request on to it's handlers, for it to be... handled (⌐■_■) :

Handler (Chemist/ Electrician): This object does the actual execution of the request. It also chains handlers together.

Now... onto our implementation/ results.

As you can see the request goes through the chain, until it hits something that can complete the request.
I hope that this help you to understand the Chain of Responsibility better.
See you next time ᕕ( ᐛ )ᕗ