Skip to content

Commit 96c16a8

Browse files
committed
Update README.md
1 parent 8983f9c commit 96c16a8

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

chain/README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,32 @@ tags:
99
---
1010

1111
## Intent
12-
Avoid coupling the sender of a request to its receiver by giving
13-
more than one object a chance to handle the request. Chain the receiving
14-
objects and pass the request along the chain until an object handles it.
12+
Avoid coupling the sender of a request to its receiver by giving more than one object a chance to
13+
handle the request. Chain the receiving objects and pass the request along the chain until an object
14+
handles it.
1515

1616
## Explanation
1717

1818
Real world example
1919

20-
> 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.
20+
> The Orc King gives loud orders to his army. The closest one to react is the commander, then
21+
> officer and then soldier. The commander, officer and soldier here form a chain of responsibility.
2122
2223
In plain words
2324

24-
> 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.
25+
> It helps to build a chain of objects. A request enters from one end and keeps going from an object
26+
> to another until it finds a suitable handler.
2527
2628
Wikipedia says
2729

28-
> 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.
30+
> In object-oriented design, the chain-of-responsibility pattern is a design pattern consisting of
31+
> a source of command objects and a series of processing objects. Each processing object contains
32+
> logic that defines the types of command objects that it can handle; the rest are passed to the
33+
> next processing object in the chain.
2934
3035
**Programmatic Example**
3136

32-
Translating our example with orcs from above. First we have the request class
37+
Translating our example with the orcs from above. First we have the `Request` class:
3338

3439
```java
3540
public class Request {
@@ -140,14 +145,16 @@ king.makeRequest(new Request(RequestType.COLLECT_TAX, "collect tax")); // Orc so
140145
```
141146

142147
## Class diagram
148+
143149
![alt text](./etc/chain.urm.png "Chain of Responsibility class diagram")
144150

145151
## Applicability
152+
146153
Use Chain of Responsibility when
147154

148-
* more than one object may handle a request, and the handler isn't known a priori. The handler should be ascertained automatically
149-
* you want to issue a request to one of several objects without specifying the receiver explicitly
150-
* the set of objects that can handle a request should be specified dynamically
155+
* More than one object may handle a request, and the handler isn't known a priori. The handler should be ascertained automatically.
156+
* You want to issue a request to one of several objects without specifying the receiver explicitly.
157+
* The set of objects that can handle a request should be specified dynamically.
151158

152159
## Real world examples
153160

0 commit comments

Comments
 (0)