Programming by contract
Programming by contract is a software design technique that specifies component obligations through preconditions, postconditions, and invariants.
Object-Oriented Software Design in C++
Programming by contract is a software design technique that specifies preconditions, postconditions, and invariants for program components and may check them during execution.
- How it is used
- Uses explicit contracts to prevent surprising behavior in classes, member functions, and subclass hierarchies.
- How deep it goes
- Explains responsibilities, runtime assertions, a CircularBuffer implementation, and inheritance constraints, but does not provide native C++ contract syntax.
- Examples
- Demonstrates contracts with CircularBuffer operations and Shipment, Expedited, and International subclasses.
- What you can do after
- Apply it by documenting and asserting class contracts, checking caller obligations, and evaluating subclass overrides for compatibility.
Read how Object-Oriented Software Design in C++ explains programming by contract →
Software Design for Python Programmers
Programming by contract is a software development technique that specifies component obligations through preconditions, postconditions, and invariants.
- How it is used
- Uses explicit contracts to prevent surprising runtime behavior in classes and methods.
- How deep it goes
- Defines three contract elements and demonstrates assertion-based implementation, while deferring native Python support and deployment strategy.
- Examples
- Demonstrates a CircularBuffer and Shipment subclasses with cost preconditions, day postconditions, assertions, and custom exceptions.
- What you can do after
- Apply it via Python assertions, predicate methods, and exceptions to specify and enforce critical class behavior.
Read how Software Design for Python Programmers explains programming by contract →
Functional Design and Architecture: Examples in Haskell
A software-design technique that expresses behavioral contracts explicitly and checks implementations against them.
- How it is used
- Uses explicit contracts to make object-oriented subsystem behavior predictable and implementations accountable.
- How deep it goes
- Defines explicit contracts and illustrates a violation, but does not detail a specific contract-checking tool or formal notation.
- Examples
- Uses ILampSwitcher, DaylightLamp, TableLamp, exceptions, global state, absent files, and memory operations as contract cases.
- What you can do after
- Diagnose implementations that violate client-facing behavioral contracts and recognize why substitutions become unsafe.
Read how Functional Design and Architecture: Examples in Haskell explains programming by contract →
Related concepts
- C++contrasts with · C++ is a statically typed, general-purpose programming language supporting procedural, object-oriented, generic, and low-level systems programming.
- preconditionuses · A precondition is a condition or requirement that must be satisfied before an operation, process, or action can proceed correctly.
- postconditionhas part · A postcondition is a property or condition that must hold after an operation completes successfully.
- inheritanceused by · Inheritance is a mechanism by which a child type or element receives properties, values, or behavior from a parent, subject to system rules and possible overrides.
- exceptionhas part · An exception is a runtime signal or object representing an abnormal condition that interrupts ordinary program flow and may be handled or propagated.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


