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)

    Morality becomes hypocrisy if it means accepting mothers’ suffering or dying in connection with unwanted pregnancies and illegal abortions and unwanted children.
    Gro Harlem Brundtland (b. 1939)

    We find that Good and Evil happen alike to all Men on this Side of the Grave; and as the principle Design of Tragedy is to raise Commiseration and Terror in the Minds of the Audience, we shall defeat this great End, if we always make Virtue and Innocence happy and successful.
    Joseph Addison (1672–1719)

    The way in which men cling to old institutions after the life has departed out of them, and out of themselves, reminds me of those monkeys which cling by their tails—aye, whose tails contract about the limbs, even the dead limbs, of the forest, and they hang suspended beyond the hunter’s reach long after they are dead. It is of no use to argue with such men. They have not an apprehensive intellect, but merely, as it were a prehensile tail.
    Henry David Thoreau (1817–1862)