Chain-of-responsibility pattern

This is an old revision of this page, as edited by Arch4ngel (talk | contribs) at 14:41, 30 January 2006 (Irrevelant to what the subject is. Even though they have the same name, it doesn't work the same way and can't help anyone understanding this design pattern.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In computer programming, the chain-of-responsibility pattern is a design pattern consisting of a source of command objects and a series of processing objects. Each processing object contains a set of logic that describes the types of command objects that it can handle, and how to pass off those that it cannot to the next processing object in the chain. A mechanism also exists for adding new processing objects to the end of this chain.

Permutations: Commands may be sent in alternate directions out, forming a tree of responsibility. Recursion could continue until the command is processed, or the entire tree has been explored. An XML interpreter (parsed, but not yet executed) might be a fitting example.

This pattern promotes the idea of loose coupling, a programming practice.

The article is originally from Perl Design Patterns Book


See also