3

I've read 3 descriptions of the command design pattern: wikipedia, dofactory and source making.

In all of them, the UML shows a relation between the client to the receiver & the concrete command, but no relation to the invoker. But in all 3 examples the client is the one that initiates the invoker and call its Execute method.

I think that should be a relation to the invoker as well. Am I missing somthing in here? Maybe even a basic UML knowladge?

djna
  • 54,992
  • 14
  • 74
  • 117
sagie
  • 2,998
  • 3
  • 22
  • 31

1 Answers1

3

That's probably a limitation of the simple examples. There is no need to have a relationship between the client and the invoker in practice.

The client could serialise the command object and send it to a remote service for execution for example, or the client may add the command to a queue for another thread to de-queue and execute later on.

Paolo
  • 22,188
  • 6
  • 42
  • 49
  • Hi there. Could you elaborate a little bit more on how the client could serialize a command object and send it to a remote service? If we imagine that there is a command object entitled "CreateGameCommand" that is a concrete "Command" class. Is this the object we would send over a TCP/IP socket to a remove service? Would the server then call the 'execute()' method on this object? Or would the client call the 'execute()' method first? Many thanks – Joeblackdev Feb 16 '11 at 13:56
  • 1
    @Joeblackdev - Yes, you would serialise the CreateGameCommand using whatever on-the-wire format you like (binary, XML, whatever) and send it to the server and the server would deserialise and call the execute() method on that object. – Paolo Feb 16 '11 at 14:15
  • Super! Thanks very much indeed for your help. – Joeblackdev Feb 16 '11 at 14:33