CQS

Creator
Creator
Seonglae ChoSeonglae Cho
Created
Created
2022 Jan 16 14:37
Editor
Edited
Edited
2026 Mar 9 15:37
Refs
Refs

Command Query Separation

  • Don't return the object created or updated
  • Do query separately

Important Principle of Imperative Programming

Conceived in Bertrand Meyer's Eiffel programming language
Every method should perform only one action: either a command that changes state or a query that returns data
Don't modify the answer when performing an action on a request
In other words, state modification and data return should be implemented separately - this is the theoretical foundation of get and set
Methods should be referentially transparent when returning values (a function is referentially transparent when it doesn't change the system's state) and should not cause side effects
While widely used, the most common problem arising from this is
Race Condition
  • Query - Returns a result value and does not change the observable state of the system. Therefore, it is free of side effects.
  • Command - Does not return a result, but instead changes the state of the system.
 
 
 
 
 

Backlinks

Recommendations