Chain of Responsibility Design Pattern


GoF Statement: Avoids coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.
Category: Behavioral
UML Diagram:  

Description of the Demonstration:

A chain (linked list) of sub-classes of Handler is constructed in ChainOfResponsibilityMain. A series of instances of E_Mail are created and passed one at a time to the first Handler in the list. If it can handle the type of the E_Mail it does so, if not it passes the E_Mail to the next Handler in the chain. The last Handler is the "default" one that handles any unknown types.


Code:

Click here to download a zip file containing all the source files and an executable of the Demonstration. See the _ReadMe.txt file in the zip.