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:

    “We say that the hour of death cannot be forecast, but when we say this we imagine that hour as placed in an obscure and distant future. It never occurs to us that it has any connection with the day already begun or that death could arrive this same afternoon, this afternoon which is so certain and which has every hour filled in advance.”
    —Marcel Proust (1871–1922)

    “Accept the place the divine providence has found for you, the society of your contemporaries, the connection of events.”
    —Ralph Waldo Emerson (1803–1882)

    “Nowadays the host does not admit you to his hearth, but has got the mason to build one for yourself somewhere in his alley, and hospitality is the art of keeping you at the greatest distance. There is as much secrecy about the cooking as if he had a design to poison you.”
    —Henry David Thoreau (1817–1862)

    “Any intelligent woman who reads the marriage contract and then goes into it, deserves all the consequences.”
    —Isadora Duncan (1878–1927)