Programming Example 12: Designing Your Own Classes


This example illustrates some important concepts related to the design of your own classes. As you study this example look for the following important concepts:

  1. The first step in designing a class is to think about the properties of the class. These properties become the data members of the class.
  2. The next step is to think about the operations that you want to be able to perform on the data. These operations are expressed in the methods that you write for the class.
  3. The data members and methods of a class can be concisely shown in a class diagram.
  4. From the class diagram you can write the code for the class.
  5. The code for this exercise will contain two classes, the class that contains the Main( ) method, and the class that you have designed.
  6. The Main( ) method will create an object using the class that you have designed.
  7. The Main( ) method now sends messages to the object to carry out the operation of the program.

The problem statement for this program is located here.

A UML class diagram for the Box class is here.

The example program is located here.  An executable of this program can be found here.