Design Recipe 3:  Designing a Class of Objects

 

Phase

Goal

Activity

Data Analysis and

Class Data

Design

to formulate data definition (for each class)

·        determine how many pieces of data describe the "interesting" aspects of the objects in this class

·        for each piece of data identify its type

·        define a constructor that initializes each data item

Examples

of

Objects

to characterize

the typical objects via examples

·        search the problem statement for examples

·        translate these examples into information objects

·        create a Test class for these examples and name the examples

Test the

Examples of Objects

to discover errors in data definitions and the constructor

·        in the new class define the toString method following the template

·        in the Test class add a print statement for each example object to enable hand-inspection that each example object has been constructed as specified

Behavior

Analysis

to identify common behaviors of the objects in the class

·        analyze the behavior of the objects in this class and identify each behavior that can be described in a simple statement

·        develop a method according to the Design Recipe for Methods in a Class

 


Design Recipes for Methods in a Class

 

Data Analysis and Definition

- to identify the data relevant for this method

·        determine how many pieces of data describe the "interesting" aspects of the objects mentioned in the problem statement

·        determine which of these data items refer to member data of the object in this class

Purpose and Header

- to name the function;

- to specify its classes of input data and its classes of output data;

- to describe its purpose;

- to formulate a header

·        choose a name for the method

·        determine the data that the method consumes and the type of result it should produce

·        write the purpose for this method; in the text identify the invoking object as this

·        write the header/contract for this method:

rType myMethod(T1 arg1, T2 arg2, ...)

Examples

of Method Use

to characterize the input-output relationship via examples

·        write a header for the test method myMethTest() in the Test class

·        search problem statement for examples

·        formulate examples as method invocations

·        define expected results and construct tests as code in the body of myMethodTest()

Template

to formulate an outline

annotate instance variables of the invoking object with this.varname

annotate instance variables of input argument objects with arg1.varname, arg2.varname, if they are not of a primitive type

Body

to define the method

develop the method body using the data specified in the template

Test

to discover mistakes ("typos" and logic)

·        run the myMethTest() in the Test class

·        check that the outputs are as predicted