[refactor] Extends Action enum in mediator pattern.

This commit is contained in:
ruslanpa 2015-02-10 09:48:22 +02:00
parent 04992483a1
commit 8980b3958c
3 changed files with 14 additions and 21 deletions

View File

@ -7,12 +7,22 @@ package com.iluwatar;
*/
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() {

View File

@ -10,7 +10,7 @@ import java.util.List;
*/
public class PartyImpl implements Party {
private List<PartyMember> members;
private final List<PartyMember> members;
public PartyImpl() {
members = new ArrayList<>();

View File

@ -17,24 +17,7 @@ public abstract class PartyMemberBase implements PartyMember {
@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