Design patterns are very general/non specific reusable solutions or templates to solve a specific design problems in software design. Which defines how the specific classes or code blocks can interact or relate to each other.
Design patterns are designed to solve commonly occurring software design problems. Which allow us to abstract the code which means we easily decouple things, maintenance will be easy . Design patterns does not provide any code but they provide a starting point to solve a specific design problem with general idea.
Chain of Responsibility
Here I am gonna write about “Chain of Responsibility” design pattern. As its name implies, the chain of responsibility pattern creates a chain of receiver objects for a sender request instruction/message. This pattern comes under behavioral patterns.
Its provides a simple mechanism, where sender is only aware of one receiver, but each receiver can contains reference to another receiver. The sender does not know who received the message. If one receiver cannot handle the request then it passes the same to the next receiver and send it down the chain until an receiver handles it. It means each receiver is only aware of the next receiver. If first receiver to handles the sender request it terminates chain.
When to use
This patterns is suitable, if there are multiple handlers for the various incoming requests, if you need multiple receivers for single request, if you want to decouple sender and receivers.
More from my site
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.