Chain Of Responsibility Pattern
- The Chain of Responsibility pattern is concerned with passing requests for action to appropriate objects.
- The Chain of Responsibility pattern works with a list of handler objects that have limitations on the nature of the requests they can deal with. If an object cannot handle a request, it passes it on to the next object in the chain. At the end of the chain, there can be either default or exceptional behaviour. To handle a request, the handler must have the appropriate resources, knowledge, and permissions.
Class diagram: (see Chain Of Responsibility Pattern code review)
Use the Chain of Responsibility Pattern when you have:
- More than one handler for a request.
- Reasons why a handler should pass a request on to another one in the chain.
- A set of handlers that varies dynamically.