Skip to content

Instantly share code, notes, and snippets.

@hackjutsu
Last active May 20, 2019 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hackjutsu/0ed197d46ad895f2ed05196c408dbb04 to your computer and use it in GitHub Desktop.
Save hackjutsu/0ed197d46ad895f2ed05196c408dbb04 to your computer and use it in GitHub Desktop.
[medium snippets] #medium #designPattern #CommandPattern
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