#95 Updated and clarified Command pattern example

This commit is contained in:
Ilkka Seppala
2015-06-30 17:52:53 +03:00
parent fb446c2991
commit db6ec3cc1a
9 changed files with 224 additions and 237 deletions

View File

@@ -1,31 +1,36 @@
package com.iluwatar.command;
public class InvisibilitySpell extends Command {
private Target target;
@Override
public void execute(Target target) {
target.setVisibility(Visibility.INVISIBLE);
this.target = target;
}
@Override
public void undo() {
if (target != null) {
target.setVisibility(Visibility.VISIBLE);
}
}
@Override
public void redo() {
if (target != null) {
target.setVisibility(Visibility.INVISIBLE);
}
}
@Override
public String toString() {
return "Invisibility spell";
}
}
package com.iluwatar.command;
/**
*
* InvisibilitySpell is a concrete command
*
*/
public class InvisibilitySpell extends Command {
private Target target;
@Override
public void execute(Target target) {
target.setVisibility(Visibility.INVISIBLE);
this.target = target;
}
@Override
public void undo() {
if (target != null) {
target.setVisibility(Visibility.VISIBLE);
}
}
@Override
public void redo() {
if (target != null) {
target.setVisibility(Visibility.INVISIBLE);
}
}
@Override
public String toString() {
return "Invisibility spell";
}
}