How to use a command template by passing run-time parameters to it

I have functionality that I encapsulate on diff commands using the Command pattern.

I create a command with the information and logic that it needs, as soon as I get some parameters only at runtime , I need to provide my commands

eg:

public class sendMessageToServerCommand implements Command {

    @Override
    public void execute(String msg){
          sendToServerTheMsg(msg);
    }
}

..
Command command=new sendMessageToServerCommand();
command.execute("msg I got on runtime");

Perhaps I should not use the command template and think about something else? offers?

Thank.

+1
source share
1 answer

, (: Runnable Callable) ; msg execute() .

Command . ; .

+3

Source: https://habr.com/ru/post/1676762/


All Articles