Pages

Wednesday, December 18, 2013

Design By Contract (Part 1)

A contract defines the rights and responsibilities of a person, as well as those of the other party. Each party respects their commitments and everyone benefits. We can use the same concept to make software modules interact.

The concept of Design by Contract was developed by Bertrand Meyer, for the language Eiffel.

Every methods in a software system does something. Before doing that, the routine may have some expectations. Meyer describes these expectations and claims as follows:

  • Preconditions - The requirements for the routine. It defines what must be true for the routine to be called.
  • Postconditions - What the routine guaranteed to do. This defines the state of the world when the routine finishes its tasks
  • Class invariants - A class ensures that this condition is always true from the perspective of a caller. By the time the routine exits and control returns to the caller, the invariant must be true.



summary of Design by Contractfrom The Pragmatic Programmer: from Journeyman to Master

No comments:

Post a Comment