
TypeScript 4 Design Patterns and Best Practices
By :

Chain of Responsibility is a pattern that allows you to have a list of classes perform certain operations on a particular object in a series of processing events. The main idea here is to establish a chain of handlers that take an object as part of a request, perform some operation, and then pass on the object to the next handler.
An analogy of this pattern is where you have a group of friends and you pass along a message on a piece of paper. Each one of you has a chance to write something or change the message completely. At the end of the chain, you announce the final response.
The main benefit of this pattern is to avoid coupling all the logic into one function or a class and instead give the chance to several middleware handlers to employ their own distinct behaviors. You can say this pattern resembles a list of Decorator functions, each decorating the same object as it passes along the list.
You want to use...