There is one thing that I wanted to mention which isn't directly tied to the subject of the command
design pattern.
And then there's this idea of command query separation because the word command appears as part of the
command design pattern.
I felt it necessary to disambiguate commands and queries then it's not an easy process.
So let's just remind ourselves what a command is.
So a command is when you're asking for an action.
And typically in the concept of commands query separation a command is something which is mutable in
the sense that it causes a mutation of the object but it doesn't have a return value it doesn't have
any results so you send a command to the goblin saying please set your attack value to 2 and you don't
get any result as the end of it.
So you just invoke the command and that's pretty much it.
Now in command queery separation we separate the commands from the queries and the second part of this
is a query.
So a query is when you are asking for information like please give me your attack value and queries
are typically not causing any mutations so a command causes an actual change in the system and returns
no value whereas a query doesn't cause any change in the system but it does give you a value and this
idea of command query separation is something that is done quite a lot in things like distributed databases
for example.
So we had this idea of command query separation where you basically split your system into separate
components and separate means of sending commands.
So asking for changes and sending queries as well.
And those can be implemented by the same components or you can completely separate the system and actually
keep two databases kind of synchronized.
There are lots of variations on the idea of command cruize separation.
Now the reason why I mentioned that is because the gang of four doesn't mention queries the Gang of
Four only mentions the command design pattern but in the context of the Gang of Four book I would say
that both commands and queries since they are wrapping some instructions in an object they are both
represented by the command design pattern.
So when somebody talks about a query being sent somewhere that is also a manifestation of the command
design pattern even though as you can see the language is a bit broken here because we've sort of called
command one thing and queried another and now I'm saying that in the Gang of Four Design Patterns the
command design pattern actually encapsulates both command and queer.
I just wanted to make this point so that you don't get confused later on.