Cognitive Scaffold

Preparing your thinking workspace

arrow_back_ios_new
MENTAL MODEL · M8897

Design by Contract

Design by Contract
SystemsHigh supportSystems Theory
Included
account_tree

Updated 2026-07-28

Loading revision record…

Summary

Design by Contract (DbC) is a method for designing computer software. This method requires software designers to define formal, precise, and verifiable interfaces for software components, thus adding preconditions, postconditions, and invariants to traditional abstract data types. The term 'contract' used in this method's name is a metaphor, as it is somewhat analogous to a commercial contract.

Definition

Design by Contract (DbC) is a method for designing computer software. This method requires software designers to define formal, precise, and verifiable interfaces for software components, thus adding preconditions, postconditions, and invariants to traditional abstract data types. The term 'contract' used in this method's name is a metaphor, as it is somewhat analogous to a commercial contract. Because 'Design by Contract' is a registered trademark of Eiffel Software, many developers use the terms 'Programming by Contract', 'Contract Programming', or 'Contract-First development' to refer to this method. Microsoft also adopts this design approach, calling it 'Code Contracts'.

How to use

Design by Contract (DbC) is a method for designing computer software. This method requires software designers to define formal, precise, and verifiable interfaces for software components, thus adding preconditions, postconditions, and invariants to traditional abstract data types. The term 'contract' used in this method's name is a metaphor, as it is somewhat analogous to a commercial contract.

Mechanism

A software design method proposed by Bertrand Meyer: it treats interactions between modules as contracts—preconditions, postconditions, and class invariants. The mechanism uses formal agreements to constrain the caller and the callee, and reports an error when a contract is violated.

Practice

In progress 0/1

Practice this model in one real situation:

Check to track your progress (stored locally)
Learning progress0%

Cases

  • The Eiffel language natively supports DbC. Modern implementations use assertions or annotations.

Common pitfalls

  • Overly strict contracts can lead to fragility. Writing only postconditions without preconditions shifts responsibility. Ignoring performance overhead.
Sources

Source support: Explicit

References currently contain only Wikipedia links; primary sources still need review.

  • link
    zh.wikipedia.orghttps://zh.wikipedia.org/wiki/%E5%A5%91%E7%BA%A6%E5%BC%8F%E8%AE%BE%E8%AE%A1ZH · Explicit
    verified
account_treeGenealogyexpand_more

RELATED MODELS