Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commited98e7a

Browse files
committed
Update chain of responsibility
1 parent0f9f3b9 commited98e7a

File tree

15 files changed

+24
-15
lines changed

15 files changed

+24
-15
lines changed

‎chain/README.mdrenamed to‎chain-of-responsibility/README.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
---
22
layout:pattern
33
title:Chain of responsibility
4-
folder:chain
5-
permalink:/patterns/chain/
4+
folder:chain-of-responsibility
5+
permalink:/patterns/chain-of-responsibility/
66
categories:Behavioral
77
language:en
88
tags:
99
-Gang of Four
1010
---
1111

1212
##Intent
13+
1314
Avoid coupling the sender of a request to its receiver by giving more than one object a chance to
1415
handle the request. Chain the receiving objects and pass the request along the chain until an object
1516
handles it.
1617

1718
##Explanation
1819

19-
Realworld example
20+
Real-world example
2021

2122
>The Orc King gives loud orders to his army. The closest one to react is the commander, then
22-
>officer and then soldier. The commander, officer and soldier here form a chain of responsibility.
23+
>anofficer, and thenasoldier. The commander, officer, and soldier form a chain of responsibility.
2324
2425
In plain words
2526

@@ -35,7 +36,7 @@ Wikipedia says
3536
3637
**Programmatic Example**
3738

38-
Translating our example with the orcs from above. First we have the`Request` class:
39+
Translating our example with the orcs from above. First, we have the`Request` class:
3940

4041
```java
4142
publicclassRequest {
@@ -66,7 +67,7 @@ public enum RequestType {
6667
}
6768
```
6869

69-
Thenthe request handler hierarchy
70+
Next, we showthe request handler hierarchy.
7071

7172
```java
7273
@Slf4j
@@ -116,7 +117,7 @@ public class OrcCommander extends RequestHandler {
116117

117118
```
118119

119-
Then we have theOrc Kingwhogives the orders and forms the chain
120+
ThOrc King gives the orders and forms the chain.
120121

121122
```java
122123
publicclassOrcKing {
@@ -136,18 +137,26 @@ public class OrcKing {
136137
}
137138
```
138139

139-
Then it is used as follows
140+
The chain of responsibility in action.
140141

141142
```java
142143
var king=newOrcKing();
143-
king.makeRequest(newRequest(RequestType.DEFEND_CASTLE,"defend castle"));// Orc commander handling request "defend castle"
144-
king.makeRequest(newRequest(RequestType.TORTURE_PRISONER,"torture prisoner"));// Orc officer handling request "torture prisoner"
145-
king.makeRequest(newRequest(RequestType.COLLECT_TAX,"collect tax"));// Orc soldier handling request "collect tax"
144+
king.makeRequest(newRequest(RequestType.DEFEND_CASTLE,"defend castle"));
145+
king.makeRequest(newRequest(RequestType.TORTURE_PRISONER,"torture prisoner"));
146+
king.makeRequest(newRequest(RequestType.COLLECT_TAX,"collect tax"));
147+
```
148+
149+
The console output.
150+
151+
```
152+
Orc commander handling request "defend castle"
153+
Orc officer handling request "torture prisoner"
154+
Orc soldier handling request "collect tax"
146155
```
147156

148157
##Class diagram
149158

150-
![alt text](./etc/chain.urm.png"Chain of Responsibility class diagram")
159+
![alt text](./etc/chain-of-responsibility.urm.png"Chain of Responsibility class diagram")
151160

152161
##Applicability
153162

@@ -157,7 +166,7 @@ Use Chain of Responsibility when
157166
* You want to issue a request to one of several objects without specifying the receiver explicitly.
158167
* The set of objects that can handle a request should be specified dynamically.
159168

160-
##Realworld examples
169+
##Real-world examples
161170

162171
*[java.util.logging.Logger#log()](http://docs.oracle.com/javase/8/docs/api/java/util/logging/Logger.html#log%28java.util.logging.Level,%20java.lang.String%29)
163172
*[Apache Commons Chain](https://commons.apache.org/proper/commons-chain/index.html)

‎chain/pom.xmlrenamed to‎chain-of-responsibility/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<artifactId>java-design-patterns</artifactId>
3232
<version>1.25.0-SNAPSHOT</version>
3333
</parent>
34-
<artifactId>chain</artifactId>
34+
<artifactId>chain-of-responsibility</artifactId>
3535
<dependencies>
3636
<dependency>
3737
<groupId>org.junit.jupiter</groupId>

‎pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
<module>facade</module>
106106
<module>flyweight</module>
107107
<module>proxy</module>
108-
<module>chain</module>
108+
<module>chain-of-responsibility</module>
109109
<module>command</module>
110110
<module>interpreter</module>
111111
<module>iterator</module>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp