Command-query separation principle
Learn the importance of the command-query separation principle.
The command-query separation principle states that a method should either execute a command (do something that creates a side effect) or answer a query (return some value), but not both.
In some cases, command-query separation creates a potential pain for client code.
If a query method alters the state of the object, it might not be possible to call it twice (to ask the same question again, for whatever reason) and get the same answer. Similarly, ...
Access this course and 1400+ top-rated courses and projects.