Designing a New Class

In this lesson, we will look at how to design a new Java class.

Design steps

Imagine that your current programming project involves the names of people. You could represent the names as strings, but you would prefer that they were objects of a data type specifically designed for names. You decide to create your own data type. You do this by writing a class definition.

In designing a class, you need to take the following steps:

  1. Name the class.
  2. Choose and name the data fields, indicating their data types.
  3. Describe the behaviors associated with objects of the class.
  4. Name the methods that will implement these behaviors.
  5. Specify the methods by writing a header and descriptive comments for each one.
  6. Write statements that use the methods and could appear in a client.
  7. Revise the method specifications, if necessary.

You would implement the class—by ...