A precondition is a Boolean condition that must be true before an operation begins. The caller must check it; the operation must behave properly when it is satisfied. section 6.3.2
Apply the idea by separating responsibility from guaranteed behavior:
- Expose a way to check a member function’s precondition, such as checking a buffer’s count before adding or removing an item. section 6.3.2
- Treat a false precondition as a call made outside the function’s obligation to behave conveniently for the caller. section 6.3.2
- Preserve substitutability in subclasses: an overriding function must not require a stronger precondition than its superclass function. section 7.5
Shipping cost
A Shipment accepts a cost greater than 0, while Expedited requires a cost greater than 5. Calling set_cost(2.00) through a Shipment pointer satisfies the superclass contract but violates the subclass contract, exposing a flawed design. Use-case descriptions apply the same idea outside code by recording what must already be true before an action starts. section 7.5 section 3.7.2







