added command sample

This commit is contained in:
Ilkka Seppala
2014-08-17 14:42:10 +03:00
parent f0e7f22266
commit 0785bccffb
11 changed files with 250 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package com.iluwatar;
public class ShrinkSpell extends Command {
private Size oldSize;
private Target target;
public ShrinkSpell() {
oldSize = null;
target = null;
}
@Override
public void execute(Target target) {
oldSize = target.getSize();
target.setSize(Size.SMALL);
this.target = target;
}
@Override
public void undo() {
if (oldSize != null && target != null) {
target.setSize(oldSize);
}
}
@Override
public String toString() {
return "Shrink spell";
}
}