Class Definition and Class Diagram

Once a programmer identifies objects and their attributes and behaviors, the programmer then focuses on encoding these objects into the program by defining classes. Each class is an object, and members of the class are attributes and behaviors of the object. Throughout the first six chapters of this book, you learned how to define a class and member attributes and member behaviors of a class using Java and C++.

Some programmers create a class diagram before they set out to define classes for an application. A class diagram illustrates classes that are used in the application and also depicts the class hierarchy , which is like a genealogical chart that shows inheritance among classes.

A class diagram shows the class name , member attributes, member behaviors, and whether those member are defined in the public, protected, or private access specifier areas of the class.

Figure 7-3 shows five class diagrams and the class hierarchy. The class hierarchy begins with the Person class, which contains some attributes and behaviors related to every person. The attributes are defined within the protected access specifier area so that they can be accessed by member functions and by functions of classes that inherit the Person class.

click to expand
Figure 7-3: Class diagrams and the class hierarchy for various student classes

Below the Person class in the class hierarchy is the Student class, which describes some attributes and behaviors found in a student. At the bottom of the class hierarchy are three classes: ContinuingEdStudent, UndergradStudent, and GradStudent. Each of these classes inherits the public and protected members of the Person class and of the Student class. In addition, each of these three classes defines attributes and member functions that are unique to their type of student.

It is a good practice to develop class diagrams and a class hierarchy for your application because programmers who develop the application and later maintain the application use this as a roadmap to understand the classes associated with the application. For example, a programmer who sets out to enhance the functionality of an application begins by reviewing class diagrams and the class hierarchy to determine if all or a portion of the functionality is already coded in an existing class. If so, the programmer can inherit the class and avoid having to write code that already exists.

OOP Demystified
OOP Demystified
ISBN: 0072253630
EAN: 2147483647
Year: 2006
Pages: 130

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: