[refactor] Separate out one method to call actions for workers.

This commit is contained in:
ruslanpa
2015-02-10 09:33:03 +02:00
parent 0fbb4f4003
commit 04992483a1
2 changed files with 42 additions and 12 deletions

View File

@@ -23,8 +23,40 @@ public abstract class DwarvenMineWorker {
System.out.println(name() + " goes to the mine.");
}
private void action(Action action) {
switch (action) {
case GO_TO_SLEEP:
goToSleep();
break;
case WAKE_UP:
wakeUp();
break;
case GO_HOME:
goHome();
break;
case GO_TO_MINE:
goToMine();
break;
case WORK:
work();
break;
default:
System.out.println("Undefined action");
break;
}
}
public void action(Action... actions) {
for (Action action : actions) {
action(action);
}
}
public abstract void work();
public abstract String name();
static enum Action {
GO_TO_SLEEP, WAKE_UP, GO_HOME, GO_TO_MINE, WORK
}
}