Command Pattern - Options

I want to use a command template in a distributed client / server environment. In fact, the methods for executing receivers must take different parameters, but I read that each class of commands should have a single method called “execute”, which should not show anything about the basic functions of receivers.

My question is how to pass call parameters from switches to different receivers via command classes? Has anyone got a simple Java example? I can't seem to find

Thank you for your help.

+3
source share
1 answer

Just pass them when building your team instance.

public class ConcreteCommand implements Command {

    private Object something;

    public ConcreteCommand(Object something) {
        this.something = something;
    }

    @Override
    public void execute() {
        // ...
    }

}

, ( , ), " ";

+7

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


All Articles