The Chain of Responsibility is known as a behavioral pattern, as it is used to manage algorithms, relationships and responsibilities between objects. The Chain of Responsibility pattern consists of a series of processing objects where each object containing the type of commands it can handle. Each object in the series either does its own task or passes to the next object if it cannot handle the request. A mechanism also exists for adding new processing objects to the end of this chain or series.
In this pattern objects in the chain are linked, typically as a one-directional linked list, with a next reference from one node to the next node. The request is passed along the chain, from one object to the next, until an object (a handler or receiver) handles it. When the request is handled, it is no longer passed on to the next level. If no object handles the request, a default object at the end of the chain can be made to handle it, or it may be that no object handles the request. Sometimes, if required, multiple objects may handle the request. Continue reading “Chain of Responsibility Design Pattern in Java”