Diagram
of
scope
of
contracts.
Error Checking |
Design By Contract |
|
During Development |
The method checks (used) data members and its
parameters. In case of an error, the method triggers an exception or returns an error. |
The designer writes strong preconditions
against data
members and
input parameters. Code to check the preconditions may be: But the programmer never, under any circumstance, writes code to check data members and parameters. NEVER! |
During Deployment |
The method code runs as written by the
programmer. Product quality code must handle any "conceivable" error. |
If there is no run-time error checking code,
the method runs
with defects
in its input; results are indeterminate. The method may work correctly
or produce a defect or crash the program or ?? If there is run-time error checking code, that code does something appropriate. It must be possible to disable the run-time code; this may be done at build-time or by the user depending on circumstances. The code might:
|
Notes |
In both styles,
error-checking code must be written for errors caused
by the operating environment. A long discussion on "conceivable" is required for all software projects. Meyer defines 3 possible outcomes in an Eiffel rescue clause.
|
double sqrt (double x)
(design by contract spec)
!Double.isNaN(x)
double sqrt (double x)
(unix error checking spec)
addClavitz (Clavitz c)
Precondition: c != null (not necessary: not worth the trouble)
Precondition: c is a Clavitz (redundant, given in method signature)
Precondition: c is valid (unclear: doesn't mean anything)
Precondition: c is initialized (too vague)
Precondition: user entered c (user's can't be part of a contract)
Precondition: there is sufficient memory to clone c (must be a run-time error check)