您的位置:首页 > 编程语言 > Java开发

java设计模式之命令模式

2016-08-09 10:27 197 查看
public interface Command{

public void exe();

}

public class MyCommand implements Command(){

private Receiver receiver;

public MyCommand(Receiver receiver){

this.receiver = receiver;

}

@Override

public void exe(){

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.exe();

}

}

public class Test{

public static void main(String args[]){

Receiver receiver =  new Receiver();

Command command = new Command(receiver);

Invoker invoker = new Invoker(command);

invoker.action();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  命令模式