Design by contract (DbC)

May 29, 2025 ยท View on GitHub

  • First introduced native support was in Eiffel programming language.
  • Think of DbC as having if checks 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.

Resources