如何通过向其传递运行时参数来使用命令模式
How to use Command pattern by passing to it runtime params
我有使用命令模式封装在 diff 命令上的功能。
我正在使用它需要的信息和逻辑创建命令,但是我如何获得一些参数仅在运行时我需要提供我的命令
例如:
public class sendMessageToServerCommand implements Command {
@Override
public void execute(String msg){
sendToServerTheMsg(msg);
}
}
..
Command command=new sendMessageToServerCommand();
command.execute("msg I got on runtime");
也许我不应该使用命令模式并考虑其他事情?建议 ?
谢谢。
我有使用命令模式封装在 diff 命令上的功能。
我正在使用它需要的信息和逻辑创建命令,但是我如何获得一些参数仅在运行时我需要提供我的命令
例如:
public class sendMessageToServerCommand implements Command {
@Override
public void execute(String msg){
sendToServerTheMsg(msg);
}
}
..
Command command=new sendMessageToServerCommand();
command.execute("msg I got on runtime");
也许我不应该使用命令模式并考虑其他事情?建议 ?
谢谢。