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();
}
}
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();
}
}
相关文章推荐
- 戏说java设计模式中的命令模式
- java设计模式_命令模式
- java设计模式_命令模式 两个不同风格的实现
- java设计模式----command模式(命令模式)
- java 设计模式-行为模式之命令模式
- Java设计模式-之Command命令模式
- java 设计模式学习笔记十二 command命令设计模式
- java设计模式_命令模式 两个不同风格的实现
- Java设计模式八:命令模式(Command)
- Java设计模式八:命令模式(Command)
- Java设计模式 Design Pattern:命令模式 Command Pattern
- Java设计模式——命令模式
- java软件体系设计模式----命令
- JAVA设计模式—命令模式(Command)
- java设计模式之Command(菜单命令)
- Java设计模式 Design Pattern:命令模式 Command Pattern
- JAVA设计模式九--Command(命令模式)
- java设计模式之命令模式Command
- java设计模式之命令模式
- 设计模式(十四)----- 命令模式(Command)----(JAVA版)