Questions tagged [command-query-separation]

Command–Query Separation (CQS) is a principle of imperative computer programming. Not to be confused with Command-Query Responsibility Segregation (CQRS), a distributed design pattern derived from CQS.

Command–Query Separation (CQS) is a principle of imperative computer programming. It was devised by Bertrand Meyer as part of his pioneering work on the Eiffel programming language.

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. In other words, asking a question should not change the answer. More formally, methods should return a value only if they are referentially transparent and hence possess no side effects. It is noteworthy that rigid implementation of this specification makes tracking the number of times queries have been issued essentially impossible; it is clearly intended as a programming guideline rather than a rule for good coding, such as avoiding the use of a goto from a nested loop.

Not to be confused with Command-Query Responsibility Segregation (), a distributed design pattern derived from CQS.

See Wikipedia for more.

52 questions
0
votes
0 answers

CQS pattern with Spring / Hibernate

I'm developing a Java/Spring/Hibernate application that adheres to the CQS (Query Command Separation) pattern. Put simply: our domain model is only used by Commands which describe some operation that needs to be done on the domain model; all read…
user2054927
  • 969
  • 1
  • 12
  • 30
0
votes
2 answers

CQS with out parameter

In CQS (Command Query Separation) it is common to have commands with a "void" return value and Queries with a return type. (or so I have learned...) Now I wonder if this COMMAND is valid then, because basically, we are doing the same thing as in a…
RubenHerman
  • 1,674
  • 6
  • 23
  • 42
0
votes
2 answers

Good Data Tier Dev & Design: What are the common bad practises in data tier development?

I am currently researching the best practises (at a reasonably high level) for application design for highly maintainable systems which result in minimal friction to change. By "Data Tier" I mean database design, Object Relation Mappers (ORMs) and…
holsee
  • 1,974
  • 2
  • 27
  • 43
0
votes
2 answers

Does the JDK source code violate command-query separation (CQS)?

These two snippets are from the JDK source code: public boolean remove(Object o) { if (o == null) { for (int index = 0; index < size; index++) if (elementData[index] == null) { fastRemove(index); …
superman
  • 51
  • 6
0
votes
0 answers

C# Query Object Pattern: Have query return IEnumerable or single result on generic interface

I have an interface which runs a query based on the query parameter and the query result public interface IQueryParam {} public interface IQueryResult {} public interface IQuery where TQueryParam : IQueryParam where…
jmzagorski
  • 1,135
  • 18
  • 42
0
votes
1 answer

Spring - passing a custom instance to a constructor

I'm trying to implement a command-query design pattern into a MVC spring based application. I have, for example, some decorated commands using decorator pattern like bellow: ICommandHandler handler = new…
Sorin Vladu
  • 1,768
  • 3
  • 21
  • 37
0
votes
1 answer

CQS queries - Auto generate ADO Mapping to View models?

I am currently working on an MVC 4 application. I am planning to implement a command query seperation pattern to enhance performance and the structure of the application. I am happy with my commands - which map my view models to my entities use…
jonho
  • 1,680
  • 2
  • 19
  • 29
1 2 3
4