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:

    Self-expression is not enough; experiment is not enough; the recording of special moments or cases is not enough. All of the arts have broken faith or lost connection with their origin and function. They have ceased to be concerned with the legitimate and permanent material of art.
    Jane Heap (c. 1880–1964)

    We should always remember that the work of art is invariably the creation of a new world, so that the first thing we should do is to study that new world as closely as possible, approaching it as something brand new, having no obvious connection with the worlds we already know. When this new world has been closely studied, then and only then let us examine its links with other worlds, other branches of knowledge.
    Vladimir Nabokov (1899–1977)

    What but design of darkness to appall?—
    If design govern in a thing so small.
    Robert Frost (1874–1963)

    Smoking ... is downright dangerous. Most people who smoke will eventually contract a fatal disease and die. But they don’t brag about it, do they? Most people who ski, play professional football or drive race cars, will not die—at least not in the act—and yet they are the ones with the glamorous images, the expensive equipment and the mythic proportions. Why this should be I cannot say, unless it is simply that the average American does not know a daredevil when he sees one.
    Fran Lebowitz (b. 1950)