Command-Query Separation (CQS) Principle
- is Command-Query Responsibility Segregation on a smaller scale
- is a principle of imperative computer programming
- it states that every method should either be a:
- command - change data
- query - returns data
CQS - Example
class OrderService {
List<Order> createNewOrderAndFindOrdersBeforeTimestamp(Order newOrder, Timestamp timestamp);
}
Applying CQS on the OrderService would result in two methods as shown below
class OrderService {
void createNewOrder(Order newOrder);
List<Order> findOrdersBeforeTimestamp(Timestamp timestamp);
}