Command Pattern - returns a value

I use a command template to send a command from a client to a server through a TCP / IP socket. The server will take the command object, deserialize it, and then call execute () on the command object. However, I need to pass the value back to the caller through the socket. Does the command template install? If not, is there a job? I looked at an example of a light switch on Wikipedia, which is great, but there are no return values. Any advice was greatly appreciated.

+7
source share
1 answer

You should not have the execute () method on Command sent to the remote server, this is bad in many ways, especially in Java. Command should represent the action the receiver should take. In this case, you need to call the method for some object.

The Command template is intended to represent actions taken or taken, and not to implement these actions. Think more about the set of instructions that you must follow.

What you are describing is basically an RPC invocation mechanism with an add-in. Do not reinvent this wheel. Considers the existing RPC mechanisms, there are many to choose from in the Java world. Then you need to decide whether the RPC is synchronous or asynchronous.

A REST- based API API is something that is popular and lasts longer than an API than any native language-specific mechanism, such as RMI.

+4
source

All Articles