Design pattern Chain of Responsibility (COR) belongs to the general design concept Divide-and-Conquer.

Imagine that we have a complex business logic with inputs and outputs, and its content is filled with numerous statements.

One of Divide-and-Conquer techniques is to apply COR in the form of a single pipeline and multiple handlers. For example, each handler implements one or multiple statements as a logical unit. The inputs are implemented as requests, and the outputs are implemented as response. The requests are passed through the pipeline and each handler is given a chance to process the requests and add something to responses. In the end, one of the handlers or end of chain handler will return the responses back to the caller.

The real life analogy will be a car assembly line (pipeline). Each worker (handler) only knows how to work on the item on hand, and pass the item down the line to next worker (handler)…

The immediate observations are:

  1. Each worker (handler) is very good at the item that he/she is assigned to.
  2. Each worker (handler) really doesn’t care who the worker up the pipeline. They just work on the item passed to them, and make sure to pass the item on hand to next worker (handler)
  3. Each worker (handler) can be easily to be replaced with another worker (handler)
  4. The quality of the item that each worker (handler) works on can be easily verified.
  5. The workflow is efficient and easy to understand and be maintained

 

References

Chain of Responsibility at Wikipedia

https://sourcemaking.com/design_patterns/chain_of_responsibility

http://www.dofactory.com/net/chain-of-responsibility-design-pattern

https://www.tutorialspoint.com/design_pattern/chain_of_responsibility_pattern.htm

 

 

 

Advertisements