Skip to content

Commit

Permalink
[refactor] Extends Action enum in mediator pattern.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslanpa committed Feb 10, 2015
1 parent 0499248 commit 8980b39
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
14 changes: 12 additions & 2 deletions mediator/src/main/java/com/iluwatar/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@
*/
public enum Action {

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

private String title;
private String description;

Action(String title) {
Action(String title, String description) {
this.title = title;
this.description = description;
}

public String getDescription() {
return description;
}

public String toString() {
Expand Down
2 changes: 1 addition & 1 deletion mediator/src/main/java/com/iluwatar/PartyImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public class PartyImpl implements Party {

private List<PartyMember> members;
private final List<PartyMember> members;

public PartyImpl() {
members = new ArrayList<>();
Expand Down
19 changes: 1 addition & 18 deletions mediator/src/main/java/com/iluwatar/PartyMemberBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,7 @@ public void joinedParty(Party party) {

@Override
public void partyAction(Action action) {
String s = this + " ";
switch (action) {
case ENEMY:
s = s + "runs for cover";
break;
case GOLD:
s = s + "takes his share of the gold";
break;
case HUNT:
s = s + "arrives for dinner";
break;
case TALE:
s = s + "comes to listen";
break;
default:
break;
}
System.out.println(s);
System.out.println(this + " " + action.getDescription());
}

@Override
Expand Down

0 comments on commit 8980b39

Please sign in to comment.