Last active
May 20, 2019 05:23
-
-
Save hackjutsu/0ed197d46ad895f2ed05196c408dbb04 to your computer and use it in GitHub Desktop.
[medium snippets] #medium #designPattern #CommandPattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Invoker { | |
private Command[] commands; | |
private Command undoCommand; | |
public Invoker() { | |
commands = new Command[2]; | |
undoCommand = new NoCommand(); | |
} | |
public void setCommand(int slot, Command command) { | |
commands[slot] = command; | |
} | |
public void onButtonWasPushed(int slot) { | |
commands[slot].execute(); | |
undoCommand = commands[slot]; | |
} | |
public void undoButtonWasPushed() { | |
undoCommand.undo(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment