A chain of objects that are responsible for handling requests. Its a series of objects that are linked together.

When a client object sends a request, the first handler in the chain will try to process it. If a handler can process the request, the request ends at this handler. If a handler cannot deal with the request, the handler will send a request to the next handler nd so on. If any handler can process it, then the request if not satisfied.
The try/catch mechanism in C# or Java implements this design pattern.

Short algorithm how to write handlers properly:
- Check if rule matches.
- If it matches, do something specific.
- If it doesn’t match, call the next filter in the list.
To achieve this, can use the Template Method pattern where each request will handle the request in a similar way following the required steps.
One thought on “Chain of Responsibility Pattern”