added mediator sample

This commit is contained in:
Ilkka Seppala
2014-08-21 20:06:49 +03:00
parent 46408565cd
commit 82f5f88964
12 changed files with 217 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
package com.iluwatar;
public abstract class PartyMemberBase implements PartyMember {
protected Party party;
@Override
public void joinedParty(Party party) {
System.out.println(this + " joins the party");
this.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);
}
@Override
public void act(Action action) {
if (party != null) {
System.out.println(this + " " + action.toString());
party.act(this, action);
}
}
@Override
public abstract String toString();
}