jargon

Design patterns·Objects, messages and the principles

the method states what must be true when you call it and what will be true when it returns, and it checks both.

Design by contract

Also calledcontract programming, preconditions and postconditions, DbC

Specifying a method by a precondition the caller must satisfy, a postcondition the method guarantees, and an invariant the object maintains throughout. It makes the division of blame explicit — a precondition violation is the caller's bug, a postcondition violation is the callee's — which is why it clarifies Liskov substitution so well. Few languages support it directly, so it usually survives as argument checks at the top of a method and assertions in tests.

Commonly confused with