All About Chain Of Responsibility Design Pattern

The chain of responsibility policies is basically used to maintain loose coupling in your software layout where there is need of client has been passed to process chain of objects. This chain of responsibility will decide that which object will process your request or it decide that whether the request needs to send to other object that is related to same chain.

Image result for chain of responsibility design pattern

When chain of responsibility policy will actually applicable?

  • When you want to convey the issue to several objects without specifying receiver.
  • When there is need of specification for handling request.
  • When there is need of determination of candidate for handling the issue.

The chain of responsibility term is recommended where multiple objects are required to do a specific task.

Who is handler?

The handler is the individual who works as an interface and receive the request from the client. After they receive request from any client then they forward or dispatch your request to chain of handlers or other objects but the reference has been given by first handler in the chain. Other handlers are unknown as other handlers are also working in the chain.

Who are concrete handlers?

The concrete handlers are considered as actual handlers, to whom the request has been forwarded.

Who are clients?

Clients are basically individuals who are originator of the request and their request are forwarded to handlers to resolve it.

Procedure for sending request in chain of responsibility

If a client is in a need to forward request to handlers about any issue then he must create a request against the issue. After the receipt of request, every handler is trying to handle the request from the client but the request is received from handler to handler. In the chain of responsibility concrete handler will receive the issue to handle the request of handler.

Benefits of chain of responsibility

There are several benefits of chain of responsibility

  • It will helps in improving the decoupling of request through handler to concrete handler
  • It will helps in simplifying the object by knowing its structure
  • This technique will help in enhancing the flexibility of object and assign duties within the chain of responsibility.
  • It makes request processing procedure not only convenient but also fast
  • The chain of responsibility policy works on the principles of command and observation used to decouple the request of the sender. Then, forward the request to relevant handler.