Skip to content

Commit 8980b39

Browse files
committed
[refactor] Extends Action enum in mediator pattern.
1 parent 0499248 commit 8980b39

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

mediator/src/main/java/com/iluwatar/Action.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,22 @@
77
*/
88
public enum Action {
99

10-
HUNT("hunted a rabbit"), TALE("tells a tale"), GOLD("found gold"), ENEMY("spotted enemies"), NONE("");
10+
HUNT("hunted a rabbit", "arrives for dinner"),
11+
TALE("tells a tale", "comes to listen"),
12+
GOLD("found gold", "takes his share of the gold"),
13+
ENEMY("spotted enemies", "runs for cover"),
14+
NONE("", "");
1115

1216
private String title;
17+
private String description;
1318

14-
Action(String title) {
19+
Action(String title, String description) {
1520
this.title = title;
21+
this.description = description;
22+
}
23+
24+
public String getDescription() {
25+
return description;
1626
}
1727

1828
public String toString() {

mediator/src/main/java/com/iluwatar/PartyImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
public class PartyImpl implements Party {
1212

13-
private List<PartyMember> members;
13+
private final List<PartyMember> members;
1414

1515
public PartyImpl() {
1616
members = new ArrayList<>();

mediator/src/main/java/com/iluwatar/PartyMemberBase.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,7 @@ public void joinedParty(Party party) {
1717

1818
@Override
1919
public void partyAction(Action action) {
20-
String s = this + " ";
21-
switch (action) {
22-
case ENEMY:
23-
s = s + "runs for cover";
24-
break;
25-
case GOLD:
26-
s = s + "takes his share of the gold";
27-
break;
28-
case HUNT:
29-
s = s + "arrives for dinner";
30-
break;
31-
case TALE:
32-
s = s + "comes to listen";
33-
break;
34-
default:
35-
break;
36-
}
37-
System.out.println(s);
20+
System.out.println(this + " " + action.getDescription());
3821
}
3922

4023
@Override

0 commit comments

Comments
 (0)