You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: chain/README.md
+125-1Lines changed: 125 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,131 @@ Avoid coupling the sender of a request to its receiver by giving
16
16
more than one object a chance to handle the request. Chain the receiving
17
17
objects and pass the request along the chain until an object handles it.
18
18
19
-

19
+
## Explanation
20
+
21
+
Real world example
22
+
23
+
> The Orc King gives loud orders to his army. The closest one to react is the commander, then officer and then soldier. The commander, officer and soldier here form a chain of responsibility.
24
+
25
+
In plain words
26
+
27
+
> It helps building a chain of objects. Request enters from one end and keeps going from object to object till it finds the suitable handler.
28
+
29
+
Wikipedia says
30
+
31
+
> 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.
32
+
33
+
**Programmatic Example**
34
+
35
+
Translating our example with orcs from above. First we have the request class
36
+
37
+
```
38
+
public class Request {
39
+
40
+
private final RequestType requestType;
41
+
private final String requestDescription;
42
+
private boolean handled;
43
+
44
+
public Request(final RequestType requestType, final String requestDescription) {
0 commit comments