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/d997f44c1c7c5fdcd3d4d93302cb0113 to your computer and use it in GitHub Desktop.
Save hackjutsu/d997f44c1c7c5fdcd3d4d93302cb0113 to your computer and use it in GitHub Desktop.
[medium snippets] #medium #designPattern #CommandPattern
public interface Command {
void execute();
}
public class ClientMain {
static public void main(String[] args) {
ReceiverA receiverA = new ReceiverA();
ReceiverB receiverB = new ReceiverB();
Invoker invoker = new Invoker();
invoker.setCommand(0, receiverA::doAction);
invoker.setCommand(1, receiverB::doAction);
invoker.onButtonWasPushed(0);
invoker.onButtonWasPushed(1);
invoker.onButtonWasPushed(1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment