next up previous
Next: 1.6.1.3 Examples Up: 1.6.1 The Design Recipe Previous: 1.6.1.1 Data Analysis and

1.6.1.2 Contract and Header

Since Scheme does not accept type declarations for function parameters, a well-written Scheme program must include a header for each function containing this information. In contrast, Java requires type declarations for all method parameters. Hence, every syntactically correct Java program includes headers for all methods. Half of this programming step is mandated by the Java language!

On the other hand, Java does not mandate the inclusion of a contract stating (i) what if any additional preconditions (beyond the the types of the arguments) must hold for the method to be called, and (ii) what relationship exists between the inputs and output of a method. The latter is often called a postcondition or output condition for the method. Well-written Java programs include preconditions and postconditions for all methods other than the trivial methods forming the data definition, e.g. stock constructors and accessors.

For methods defined over composite types (abstract classes at the top of composite class hierarchies), the contract information should be attached to the abstract method definition in the top class.



Corky Cartwright
2000-01-07