Chain-of-responsibility pattern: Difference between revisions

Content deleted Content added
Bluelinking 1 books for verifiability.) #IABot (v2.1alpha3
m v2.02 - Fixing innerlinks / WP:WCW project (Link equal to linktext)
Line 37:
[[File:w3sDesign Chain of Responsibility Design Pattern UML.jpg|frame|none|A sample UML class and sequence diagram for the Chain of Responsibility design pattern. <ref>{{cite web|title=The Chain of Responsibility design pattern - Structure and Collaboration|url=http://w3sdesign.com/?gr=b01&ugr=struct|website=w3sDesign.com|accessdate=2017-08-12}}</ref>]]
 
In the above [[Unified Modeling Language|UML]] [[Class diagram|class diagram]], the <code>Sender</code> class doesn't refer to a particular receiver class directly.
Instead, <code>Sender</code> refers to the <code>Handler</code> interface for handling a request (<code>handler.handleRequest()</code>), which makes the <code>Sender</code> independent of which receiver handles the request.
The <code>Receiver1</code>, <code>Receiver2</code>, and <code>Receiver3</code> classes implement the <code>Handler</code> interface by either handling or forwarding a request (depending on run-time conditions).
<br>
The [[Unified Modeling Language|UML]] [[Sequence diagram|sequence diagram]]
shows the run-time interactions: In this example, the <code>Sender</code> object calls <code>handleRequest()</code> on the <code>receiver1</code> object (of type <code>Handler</code>).
The <code>receiver1</code> forwards the request to <code>receiver2</code>, which in turn forwards the request to <code>receiver3</code>, which handles (performs) the request.