Logistics for using the design recipe for designing classes and methods

 

Class Data Analysis and Design

 

Preparing the infrastructure

Create the file myClass.java where the class myClass will be defined.

Create the file myClassTest.java for testing the objects and methods in this class. Use the standard header - extending JPFalt.

 

Data analysis and definition

Identify the problem class of data and its properties

Translate this into separate data items and represent each as an instance variable.

Define the instance variables in the class myClass.

Define the constructor for myClass.

 

Examples of Objects

Define the method toStringData, following the template below.

The tests of objects should be placed inside of testMyClass function in the class myClassTest.

Make examples of definitions of objects in this class (using the constructors) and use println function to display the object member data values.

 

Behavior Analysis and Method Design

 

Identifying the desired methods

Analyze the behavior of objects in this class and identify common behaviors. Formulate a description of the problem each behavior addresses. Give a name to each problem.

 

For each problem follow the Design Recipe for Methods in a Class to develop a method that solves this problem.

 

Designing Method in a Class

 

Data analysis and definition

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 signature

Determine the data the method will consume and the type of result it should produce. Identify the origin and type of all data the method will consume: internal instance variables, external data of the primitive types, or externally defined instance of this class

Write the purpose and signature for this method (myMethod) in the myClass class. Include the { } to define (a temporary) empty method body.

The purpose statement must include the word this referring to the object which invokes the method.

 

Examples

Design examples as you would for any standalone function.

 

Write a function header for a function myMethodTest() in the myClassTest class and add a statement to print the test header:

      testHeader("myFunctionName(argumentList)");

 

Place examples as tests in the body of this function.

Each example should be written as follows:

      expected(resultValue);

      test( myFunctionName(argumentList));

 

Template

Write a template for this method - include it as a comment in the myMethod body.

Include in the template all member data items for this object and for any object that the function receives as argument.

 

Function Body

Use the template to guide you in designing the body of the method.

 

Tests

Run the tests and record your results.