Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command Pattern in GOF vs CQRS meanings

When Looking at the command pattern a found a slight difference. May be some is able to more clearify this.

When looking at Gang Of Four it says that each command has a Execute Method see for example: http://www.blackwasp.co.uk/Command.aspx like:

myCommand.Execute(myValue);

Now when i look at the commands how there are used in CQRS (Greg Young) i see that this commands don't have an execute method. They are only some kind of "Command Instruction" instance. Similar things are said in the CQRS webcasts like.

And the command is handled by the domainobject. like

class myDomainObject
{
    void UpdateValue(UpdateValueCommand cmd){
        this.value = cmd.value;
    }
}

Is it right that it's just another CommandPattern definition like "CQRS-Command Pattern" ? So that when talking of a command it may have slight diffent meaning in a "common" or "cqrs" context? or am I missing something the command pattern or CQRS implementation?

like image 807
Boas Enkler Avatar asked May 07 '15 08:05

Boas Enkler


1 Answers

Good question.

Command pattern in its raw form is like GOF says.

In CQRS the command is just a DTO (data transfer object) because CQRS is, in most cases, implemented with events or message bus that handles the command. In CQRS you send the command to the system and the system has some kind of bus or event architecture that allows autonomous component to subscribe to handle the command; in this way you can create a responsibility chain and it is more SOLID to, for example, work with read and write models.

It is more a chain of responsibility pattern that command pattern but you keep the advantages of command pattern because you still have commands and can, for example, implement UNDO an action easily like in command pattern.

This link can help you to understand CQRS better.

like image 66
jlvaquero Avatar answered Oct 06 '22 02:10

jlvaquero