Skip to main content

Chain of responsibility design pattern


In this behavioral design pattern, request is handled using a chain of objects. This is used to eliminate series of if...else if...else if... statements. Thus, each of the processing object contains only the related logic (as in an if statement). It is also possible to execute all the processing objects.
Since the chain work independently new handlers can be added easily, and also existing handlers can be removed.

Image source wikipedia

Let's see a sample.