Design Patterns · Senior · Question 31 of 75
What does the Command-Query Separation (CQS) principle require?
- ✓Correct answer: A method either changes state or returns data
- 2Commands and queries must be stored in different databases
- 3API queries are made only with the GET method
Explanation
A query function without side effects is predictable and safe to call repeatedly (e.g. during render). There are exceptions (stack.pop()), but the principle helps avoid surprises like a getter that makes a request. CQRS is the architectural extension of this idea.