Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface Command() {
- public void execute();
- }
- public class MyCommand implements Command {
- private Receiver receiver;
- public MyCommand(Receiver receiver) {
- this .receiver = receiver;
- }
- @Override
- public void execute() {
- receiver.action();
- }
- }
- public class Receiver {
- public void action() {
- System.out.println("command received!")
- }
- }
- public class Invoker {
- private Command command;
- public Invoker(Command command) {
- this. command = command;
- }
- public void action() {
- command.execute();
- }
- }
- public class Test {
- public static void main(String[] args) {
- Receiver receiver = new Receiver();
- Command cmd = new MyCommand(receiver);
- Invoker invoker = new Invoker(cmd);
- invoker.action();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement