Design by Contract
Updated 2026-07-28
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'.
Introduction
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/1Practice this model in one real situation:
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.
- zh.wikipedia.orghttps://zh.wikipedia.org/wiki/%E5%A5%91%E7%BA%A6%E5%BC%8F%E8%AE%BE%E8%AE%A1verified
account_treeGenealogyexpand_more
PRIVATE NOTES · Only visible to you
SAVED Q&A
ENTRY Q&A · Private saving available
Ask with a clear boundary
thinkingmodels answers from published entry context only.
Your question is sent to thinkingmodels. The answer uses public entry context only.
RELATED MODELS