page_title: Chain-of-responsibility pattern
section_title: UML class and sequence diagram
hierarchical_section_title: Chain-of-responsibility pattern / Structure / UML class and sequence diagram
caption_attribution_description: English: A sample UML class and sequence diagram for the Chain of Responsibility design pattern.
context_page_description: In object-oriented design, 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 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 if ... else if ... else if ....... else ... endif 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 dispatchers, 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 might work in this manner.
context_section_description: In the above UML class diagram, the Sender class doesn't refer to a particular receiver class directly.
  Instead, Sender refers to the Handler interface for handling a request (handler.handleRequest()), which makes the Sender independent of which receiver handles the request.
  The Receiver1, Receiver2, and Receiver3 classes implement the Handler interface by either handling or forwarding a request (depending on run-time conditions).
  
  The UML sequence diagram
  shows the run-time interactions: In this example, the Sender object calls handleRequest() on the receiver1 object (of type Handler). 
  The receiver1 forwards the request to receiver2, which in turn forwards the request to receiver3, which handles (performs) the request.
caption: A sample UML class and sequence diagram for the Chain of Responsibility design pattern. [4]
exif: {}