Design by contract (DbC)
May 29, 2025 ยท View on GitHub
- First introduced native support was in Eiffel programming language.
- Think of DbC as having
ifchecks before and after you manipulate data inside live code. Yes they are basically assertions. - Major components of DbC:
- Precondition
- Conditions that must be met before a function is executed.
- Client obligations, supplier benefits.
- Postcondition
- Conditions that must be met after a function is executed.
- Client benefits, supplier obligations.
- Invariants
- General rules that must be true for the entire duration of the function.
- Conditions that must be met before and after a function is executed.
- Precondition
Resources
- How are
TDDandDbCrelated?- TDD is external to business logic, DbC is internal.
- Code Contracts in
.NET - Design by Contract and Assertions
- Design by Contract in C3 (a successor to C)