Command-query Separation - Connection With Design By Contract

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 program is expressed as assertions embedded in the source code, describing the state 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. CQS may also prevent the occurrence of certain kinds of heisenbugs.

Read more about this topic:  Command-query Separation

Famous quotes containing the words connection with, connection, design and/or contract:

    ... instinct is the direct connection with truth.
    Laurette Taylor (1887–1946)

    The connection between our knowledge and the abyss of being is still real, and the explication must be not less magnificent.
    Ralph Waldo Emerson (1803–1882)

    The reason American cars don’t sell anymore is that they have forgotten how to design the American Dream. What does it matter if you buy a car today or six months from now, because cars are not beautiful. That’s why the American auto industry is in trouble: no design, no desire.
    Karl Lagerfeld (b. 1938)

    A contract for better for worse is a contract that should not be tolerated.
    George Bernard Shaw (1856–1950)