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
1
vote
1 answer

Vertical Slice Architecture - What should go in the Controller, Command/Query, Response, CommandHandler?

After some thought and consideration, I have decided to restructure my existing directory structure of an app I have which is currently sliced Horizontally (in layers), into a Vertical Sliced approach. To match the desired structure I changed my…
Vahe
  • 1,699
  • 3
  • 25
  • 76
1
vote
1 answer

Command Query Separation - Asynchronous Commands that return values

I have adopted the Command Query Separation principle in a project. However, I am not adhering to it strictly as we have a need for Commands to return values. Many people refer to this article which is a great explanation of this concept: However,…
JTech
  • 3,420
  • 7
  • 44
  • 51
1
vote
4 answers

Command Query Separation violation

What do you think about if(!DoSomething()) return; In Clean Code this is viewed as violation of Command Query Separation. But how can we understand if something in command DoSomething() went wrong? What about sql command (ex: void Delete(Table))?…
1
vote
1 answer

Confusion about interaction with other domains

We're creating a new application for an entirely new domain model (and Bounded Context) 'Appointment'. We chose to combine CQS with Hexagonal Architecture (using ports and adapters) for our new domain. Our package structure mainly looks like…
1
vote
4 answers

CQS and ASP.NET MVC Actions

Those who have read about CQS principle know that: CQS 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. Speaking of ASP.NET MVC Actions, does CQS indicate…
Mosh
  • 5,944
  • 4
  • 39
  • 44
1
vote
2 answers

How to return result while applying Command query separation (CQS)

I am separating my query and command on service side like this: public class ProductCommandService{ void AddProduct(Product product); } public interface ProductQueryService{ Product GetProduct(Guid id); Product[]…
barteloma
  • 6,403
  • 14
  • 79
  • 173
1
vote
0 answers

Pull Parsing and CQS

I'm creating a pull parser and it relies heavily on reading characters in a sequential way. The state of the parser changes as characters are read, so we can say there is a "context" that designates how next characters are interpreted. The problem…
SuperJMN
  • 13,110
  • 16
  • 86
  • 185
1
vote
2 answers

Change current implementation of basic MVVM to adhere to SOLID pattern

I have been writing all my MVVM application with basic design pattern generally mentioned in MVVM examples available online. The pattern that I am following is described below: Model This section include DTO classes with their properties and…
Balraj Singh
  • 3,381
  • 6
  • 47
  • 82
1
vote
0 answers

Understanding event-driven in a Spring MVC application

I've read the code from this Spring MVC application: https://github.com/spring-guides/tut-rest/tree/master/6/complete/src/main/java/com/yummynoodlebar/core/events I don't understand the role of those classes from events folder. How can I catch such…
Sorin Vladu
  • 1,768
  • 3
  • 21
  • 37
1
vote
2 answers

CQS and CRUD operation

I working on high-scalability web site for learning purpose. I decided to use CQS pattern and some ideas of CQRS. I have separate write and read layers used by command handlers and event handlers which system sends and receives from message buses…
geek
  • 596
  • 8
  • 26
0
votes
1 answer

Can I break CQS to ensure less chatty web service interfaces?

I have a .NET WPF smart client calling a .NET WCF web service. The web service does most of the work and returns a small amount of information to the client. As such it's not entirely unlike a browser. The client calls the web service, and at the…
Neil Barnwell
  • 41,080
  • 29
  • 148
  • 220
0
votes
1 answer

CQS: Who is responsible for data caching and when?

When and who should be responsible for caching data into local data store from API GET requests in DDD architecture with CQS based use cases? First thing that comes to mind: Initiate a Query to get some data from local data store and if it is…
0
votes
1 answer

In CQ(R)S, is it OK to use a Command as a parameter of a model constructor?

Say I have a CreateUser command: class CreateUser { public string $email; public string $password; public string $firstName; public string $lastName; public LocalDate $dateOfBirth; public ?string $location; } Is it OK if my…
BenMorel
  • 34,448
  • 50
  • 182
  • 322
0
votes
2 answers

Can not implicity convert type Systems.Collection.Generic.List to Proj.Areas.Management.Models.FeedEventViewModel

I'm trying to convert a view model to list and then return it to the view but am getting the cannot implicity convert type error. Code: public ActionResult Index(FeedEventCommand command) { var feedEventViewModel = new FeedEventViewModel { …
Alex
  • 443
  • 3
  • 18
0
votes
1 answer

Property seems to be changing between method calls, but no code is supposed to be changing it

I have an Octet class that is suppose to "package" eight samples and then send them forward. It has methods to add a new sample, check if it is already full, and to extract a Frame datastructure built from the eight values from the Octet. The Octet…
heltonbiker
  • 26,657
  • 28
  • 137
  • 252