7900 shaares
161 private links
161 private links
It states that every method should either be a command that performs an action, or a query that returns data to the caller, but not both.
More formally, methods should return a value only if they are referentially transparent and hence possess no side effects.
Even in single-threaded programs, it is sometimes arguably significantly more convenient to have a method that is a combined query and command. Martin Fowler cites the pop() method of a stack as an example.