Let’s develop a simple inheritance hierarchy with five levels (represented by the UML class diagram in Fig. 11.2). A university community has thousands of CommunityMember
s.
These CommunityMember
s consist of Employee
s, Student
s and alumni (each of class Alumnus
). Employee
s are either Faculty
or Staff
. Faculty
are either Administrator
s or Teacher
s. Some Administrator
s, however, are also Teacher
s. We’ve used multiple inheritance to form class AdministratorTeacher
. With single inheritance, a class is derived from one base class. With multiple inheritance, a derived class inherits simultaneously from two or more (possibly unrelated) base classes. We discuss multiple inheritance in Chapter 21, Other Topics, but multiple inheritance is generally discouraged.
Each arrow in the hierarchy (Fig. 11.2) represents an is-a relationship. For example, as we follow the arrows in this class hierarchy, we can state “an Employee
is a CommunityMember
” and “a Teacher
is a Faculty
member.” CommunityMember
is the direct base class of Employee
, Student
and Alumnus
. In addition, CommunityMember
is an indirect base class of all the other classes in the diagram. An indirect base class is inherited from two or more levels up the class hierarchy.
Starting from the bottom of the diagram, you can follow the arrows upwards and apply the is-a relationship to the topmost base class. For example, an AdministratorTeacher
is an Administrator
, is a Faculty
member, is an Employee
and is a CommunityMember
.
3.144.94.187