Holger Thiemann
Holger Thiemann

Reputation: 1082

Any pattern name for commands that are handled instead of executed

The command pattern of Gof describes a command with an execute method. This is in Wpf and Silverlight for example defined in the ICommand interface, enriched with a CanExecute Method. This type of commands encapsulates the parameters for the action to be executed, and the logic to call the execution. To do that it must know the execution context (where the execute method can call the desired method and where the canexecute method can validate if its possible). This type of commands are responsible for their own execution.

In CQRS for example an other type of "Command" is used. It has no Execute Method on its own and is not responsible for its own execution. It just encapsulates the needed parameters and is handled by a command handler, that makes the call. This type of command has the advantage that it does not need to know the execution context, is therefor easier to serialize and it has more separation of concerns.

My question know is: The first typ of command is covered in the Gof "Command pattern". Is there any pattern name for the seccond type of command?

I have an application where I want to use both types of command and I have to choose different names for them. I tend to "Command" and something like "HandledCommand" but I would like to choose a well known pattern name if there is one.

Upvotes: 0

Views: 178

Answers (1)

Fuhrmanator
Fuhrmanator

Reputation: 12882

Maybe the answer is found in the Command Processor pattern, as defined in POSA Vol. 1 and described here: http://www.dre.vanderbilt.edu/~schmidt/cs282/PDFs/8-Services-and-IPC-parts-7-8-and-9.pdf and in a video at https://www.youtube.com/watch?v=PJvnMP94Kqw

Intent

  • Packages a piece of application functionality—as well as its parameterization in an object—to make it usable in another context, such as later in time or in a different thread

Applicability

  • When there’s a need to decouple the decision of what piece of code should be executed from the decision of when this should happen

  • e.g., specify, queue, & execute service requests at different times

  • When there’s a need to ensure service enhancements don’t break existing code

I reproduced the class diagram using PlantUML:

Command Processor UML class diagram of Structure and Participants


The Command Bus pattern http://php-and-symfony.matthiasnoback.nl/2015/01/responsibilities-of-the-command-bus/ is a related idea that applies in web development.

Upvotes: 1

Related Questions