Google
 
   
Login
Username:

Password:


Lost Password?

Register now!
Search
Main Menu
top books
Polls
What do you think about php-deluxe.net?
Excellent!
Cool
Hmm..not bad
What the hell is this?
encyclopedia
recommendation
compare webbrowser
Freenet DSL
Who's Online
7 user(s) are online (7 user(s) are browsing encyclopedia)

Members: 0
Guests: 7

more...
browser tip
recommendation!
Sponsored
partner
Germany Next Topmodel
germanys next topmodel germanys next topmodel

Command-query separation

Command-query separation (CQS) is a principle of object-oriented computer programming. It was devised by Bertrand Meyer a part of his pioneering work on the Eiffel programming language.

It states that every Method (computer science) 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 referential transparency and hence possess no Side-effect (computer science)s.

= Connection with Design by Contract =

Command-query separation is particularly well suited to a Design by Contract (DbC) methodology, in which the design of a Computer program is expressed as assertions embedded in the source code, describing the State (computer_science) of the program at certain critical times. In DbC, assertions are considered design annotations---not program logic---and as such, their execution should not affect the program state. CQS is beneficial to DbC because any value-returning method (any query) can be called by any assertion without fear of modifying program state.

In theoretical terms, this establishes a measure of sanity, whereby one can reason about a program s state without simultaneously modifying that state. In practical terms, CQS allows all assertion checks to be bypassed in a working system to improve its performance without inadvertently modifying its behaviour.

= Broader Software Engineering Impact =

Even beyond the connection with Design by Contract, CQS is considered by its adherents to have a simplifying effect on a program, making its states (via queries) and state changes (via commands) more comprehensible in a manner reminiscent of how Edsger Dijkstra s admonition against gotos did the same for control flow.

CQS can also be applied outside of object-oriented programming. There is nothing inherently object-oriented about the separation of side-effects and return values, and so CQS can be profitably applied to any programming paradigm that requires reasoning about side-effects.

= Criticism =

Some claim that CQS makes it difficult to implement around sets of calls, they can also trivially solved by breaking CQS and implementing the operation as a single method that encapsulates the necessary locking. Hence, the benefits of CQS may find themselves sacrificed for expediency.