| TeachJava 2004
|
The Java Design Recipe
- Define the data.
- Determine what forms of data will the program process.
- Write precise definitions in English for each such form of data.
- Implement these definitions as classes. If working in full
Java, include constructors, accessors, and definitions of
appropriate toString, equals, and
hashCode methods.
- Define examples of each form of data in JUnit test class
corresponding to the form of data and test that they are
equal to their string representations (given by
toString).
- If using full Java, include code in the test methods to test
the equals and hashCode methods and any
non-trivial constructors and accessors.
- For each class, determine the methods that process that
form of data and write their signatures (headers) in the class bodies.
For any method that is defined for mixed
data, include a abstract method signature in the most general
class for which the method is defined and concrete method signatures in
all of the concrete classes where it is defined.
- Write contracts (purpose statements) for all of the non-trivial
methods in your program specifying what they require and they produce. Attach each
contract as comment to the most general declaration of the
corresponding method.
- For each program method m, devise a collection of examples
specifying how you expect that method to behave. Write these
examples as test methods in a JUnit test case class.
- For each program method, select an appropriate template,
recognizing that self-references in the class of the method suggest
that recursive delegation is appropriate.
- For each program method, write the body,
recognizing that self-references in the class of the method
suggest that recursive delegation is appropriate.
- Test each method (from step 2.) using the JUnit test case
classes for the program. Include additional test cases suggested by
issues that arose during coding and testing.