Last active
May 20, 2019 05:23
-
-
Save hackjutsu/d997f44c1c7c5fdcd3d4d93302cb0113 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 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