Java – command mode – parameters
•
Java
I want to use command mode in a distributed client / server environment In essence, the "execute" method of the receiver requires various parameters, but I read that each command class should have a unified "execute" method, which should not reveal the underlying functions of the receiver
My question is, how do I pass call parameters from the switch to different receivers through the command class? Does anyone have a simple java example? I can't seem to find anything
Thanks for your help.
Solution
Just pass them when constructing command instances
public class ConcreteCommand implements Command { private Object something; public ConcreteCommand(Object something) { this.something = something; } @Override public void execute() { // ... } }
Or if you really need to pass parameters (because they represent working state rather than algorithm state), you should do so and call them "strategy pattern" instead of;)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码