This article describes the 'Chain of Responsibility' design pattern. This is a
behavioral design pattern, a category of
design pattern used by software engineers, when writing computer programs.
Table of Contents
Introduction
The "Chain of responsibility" pattern is a
design pattern, used in software engineering, to define the act of passing a piece of data down a chain of processors. Each processor decided whether to deal with the data or pass it straight on. A variation to this is
the "tree of responsibility", where each processor can itself also decide which direction to send the data.
It is defined as a
behavioral design pattern because it affects what order the program acts on the data it is processing.
Benefits
Benefits of this pattern are that data is processed in a timely, queued and organised way.
This pattern also allows developers to easily add extra modules on the end of the chain, making the code more extensible.
Examples of the pattern
An example of this pattern would be processing of a log message. Different level log messages may be dealt with differently. For example, the first processor may just write it to file, but a later processor (if the log message is high enough) could email
the message, or trigger an alert of some kind.
Another example is the collection of data for a report. A report class with an identifier could be passed through such a chain, each processor responsible for accessing its own stores, for information to add to the final report. As extra systems are added,
they too can be strapped on the end of the chain, providing extra information to the report class.
See Also
Link to domain parent articles and related articles in TechNet Wiki.
Community Resources
These are the external links, including links to Microsoft and TechNet sites that are non-Wiki- http://www.dofactory.com/Patterns/PatternChain.aspx - Definition and C# example
References section
Use this section if you pulled source material and ideas from other sites, blogs, or forums. Make sure you have permission from authors to use their material.