Defining and enforcing software behavior by construction
Design by Contract™ is a method for building software in which the expected behavior of every component is explicitly defined, checked, and enforced.
Instead of relying solely on testing to detect errors after they occur, Design by Contract makes correctness a structural property of the system.
The problem it solves
Most software systems fail because critical assumptions remain:
- Implicit
- Informal
- Unchecked
Documentation drifts.
Tests cover samples, not guarantees.
As systems evolve, hidden assumptions break silently.
Design by Contract addresses this by making assumptions executable.
The core mechanism
Each software component is governed by a contract consisting of:
- Preconditions
What must be true before a component is used. - Postconditions
What the component guarantees after execution. - Invariants
Conditions that must always remain true for the system to be valid.
These contracts define the legal space of software behavior.
Violations are detected automatically, at the moment they occur.
What this changes in practice
Design by Contract shifts error detection:
- From late testing to immediate execution
- From implicit knowledge to explicit rules
- From defensive coding to enforced correctness
As a result:
- Errors surface closer to their cause
- Component interactions become predictable
- System evolution becomes safer
Contracts serve simultaneously as:
- Executable specifications
- Runtime checks
- Precise documentation that cannot lie
Why most languages fall short
In many environments, contracts are:
- Informal comments
- Optional assertions
- External annotations
This makes them:
- Easy to ignore
- Hard to maintain
- Disconnected from tools
Design by Contract only delivers its full value when it is native to the language and understood by the development environment.
Design by Contract™ in EiffelStudio
EiffelStudio integrates Design by Contract at every level:
- Language constructs
- Compiler support
- Runtime enforcement
- Tooling awareness
Contracts are not an add-on.
They are part of how software is written, analyzed, and executed.
This tight integration allows teams to reason about software behavior with a level of precision that testing alone cannot provide.
When Design by Contract is the right choice
Design by Contract is particularly effective for:
- Long-lived systems
- Safety-critical or financial software
- Complex domains with evolving requirements
- Teams that prioritize correctness and maintainability
- It can also help with the creation of disposable or exploratory code as a basis for future expension.
Is Design by Contract for me?
“It simply changed my life as a developer”. That’s what countless people tell us. Will you too? Find out the facts by consulting the following resources:
- Introduction to Design by Contract or the Design by Contract section in the Eiffel Documentation.
- Design by Contract™ presentation series.
- The classic: Object-Oriented Software Construction, 2nd Edition by Bertrand Meyer, the reference on object technology and modern software engineering practice often referred to as “the O-O Bible.”
- The textbook: Touch of Class: Learning to Program Well with Objects and Contracts, by Bertrand Meyer, that makes learning programming fun and rewarding.
- Downloading EiffelStudio.
Design by Contract™ was introduced by Bertrand Meyer and has influenced many modern correctness approaches. Eiffel remains the only environment where it is implemented as a coherent, end-to-end method.
