module command.remoteundostatus.ceilingfanoffcommand; import command.remoteundostatus.command; import command.remoteundostatus.ceilingfan; class CeilingFanOffCommand : Command { CeilingFan ceilingFan; int prevSpeed; this(CeilingFan ceilingFan) { this.ceilingFan = ceilingFan; } void execute() { prevSpeed = ceilingFan.getSpeed(); ceilingFan.off(); } void undo() { switch (prevSpeed) { case CeilingFan.HIGH: ceilingFan.high(); break; case CeilingFan.MEDIUM: ceilingFan.medium(); break; case CeilingFan.LOW: ceilingFan.low(); break; case CeilingFan.OFF: ceilingFan.off(); break; default: break; } } }