1.5.1.1 Data Analysis and Design
Keywords: current

Next: 1.5.1.2 Contract and Header Up: 1.5.1 The Design Recipe Previous: 1.5.1 The Design Recipe

###
1.5.1.1 Data Analysis and Design

Our first task in writing a program is to understand and define the data that the program will process. We must compile an inventory of the various forms of data that can appear as program inputs and outputs and determine how to represent their ``relevant'' properties as Java data objects. In scientific problem solving, this process is often called ``data modeling'' or simply ``modeling''. For each distinct form of data, we must define a Java class with fields that represent the relevant properties of each object of that form. We use the composite pattern to specify which different forms of data belong to the same more general category of data. In the preceding section, for example, we grouped the `Empty` department directory and non-empty `Cons` department directories together using the composite pattern to form the more general category `DeptDirectory`.

Java class definitions are more general and flexible than data definition facilities for defining structures in procedural and fucntional languages because because they enable the programmer to determine (i) exactly which primitive operations, including constructors, the new form of data will support, (ii) how objects will be printed as strings, (iii) and the types of object fields and methods.

The extra generality provided by Java comes at a price. A Java programmer must write far more text to define a class than a functional programmer does to define a comparable struct.

It is a good idea to define a collection of examples for each concrete class in a data definition. These examples can be defined as static fields of the class or as static fields of an accompanying test class.

Next: 1.5.1.2 Contract and Header Up: 1.5.1 The Design Recipe Previous: 1.5.1 The Design Recipe