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:
- 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.
- 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.
- The data members and methods of a class can be concisely shown in a class diagram.
- From the class diagram you can write the code for the class.
- The code for this exercise will contain two classes, the class that contains
the Main( ) method, and the class that you have designed.
- The Main( ) method will create an object using the class that you have designed.
- 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
A UML class diagram for the Box class is
The example program is located
here. An executable of this program can be found