Content deleted Content added
No edit summary |
Added a 'dubious' tag to a statement about how this pattern is an object oriented version of if else if else... for that to be true, the pattern would have to enforce that if one processing object is executed (in other words, is true) then the other processing objects are not executed, as you would experience in an if else if else type block. As it is, any or all of the processing objects could be executed, and that is not possible in an if else if else block. |
||
Line 1:
In [[object-oriented design]], the '''chain-of-responsibility pattern''' is a [[design pattern (computer science)|design pattern]] consisting of a source of [[Command pattern|command objects]] and a series of '''processing objects'''.<ref>{{Cite web |url=http://www.blackwasp.co.uk/ChainOfResponsibility.aspx |title=Archived copy |access-date=2013-11-08 |archive-url=https://web.archive.org/web/20180227070352/http://www.blackwasp.co.uk/ChainOfResponsibility.aspx |archive-date=2018-02-27 |url-status=dead }}</ref> Each processing object contains logic that defines the types of command objects that it can handle; the rest are passed to the next processing object in the chain. A mechanism also exists for adding new processing objects to the end of this chain. Thus, the chain of responsibility is an object oriented version of the <code>if ... else if ... else if ....... else ... endif</code>{{Dubious |Talk ifelseifelseifelseendif|date=August 2020}} idiom, with the benefit that the condition–action blocks can be dynamically rearranged and reconfigured at runtime.
In a variation of the standard chain-of-responsibility model, some handlers may act as [[dynamic dispatch|dispatcher]]s, capable of sending commands out in a variety of directions, forming a ''tree of responsibility''. In some cases, this can occur recursively, with processing objects calling higher-up processing objects with commands that attempt to solve some smaller part of the problem; in this case recursion continues until the command is processed, or the entire tree has been explored. An [[XML]] [[Interpreter (computing)|interpreter]] might work in this manner.
|