Page 514 - Introduction to Programming with Java: A Problem Solving Approach
P. 514

                480 Chapter 12 Aggregation, Composition, and Inheritance
    Organism Is alive.
 Eukaryote Each cell has nucleus.
  Plant
Has more than one cell. Is photosynthetic.
Animal
Has more than one cell.
Is vascular.
 Arthropod Has exoskeleton. Is segmented.
 Prokaryote
Has one cell with no nucleus.
    Bacteria Normal
Archaea Extreme
      Apago PDF Enhancer
Reptile Mammal
Lays eggs. Has mammary glands.
Has scales. Has hair.
Vertebrate Has backbone. Has braincase.
Figure 12.8 Biological example of an inheritance hierarchy
The types at the very bottom of a real-life biological inheritance hierarchy do not appear in Figure 12.8, because the complete hierarchy is too big to display in one figure. What’s actually at the bottom are species, like Homo sapiens (human beings). In nature, reproduction is possible only among members of the same spe-
cies. Similarly, in an ideal OOP computer program, the only realizable (instantiable) types are the types at the very bottom of inheritance hierarchies. Organizing an inheritance hierarchy so that all realizable (instantiable) types appear only at the lowest level (the leaves of a hierar- chical tree) minimizes duplication, and it minimizes maintenance and enhancement labor.
UML Class Diagrams for Inheritance Hierarchies
Figure 12.9 shows a UML class diagram for an inheritance hierarchy that keeps track of people associated with a department store. The top class, Person, is generic. It contains data and methods that are common to all classes in the hierarchy. Classes below the top class are more specific. For example, the Customer and Employee classes describe specific types of people in the department store. Since there are two distinct types of store employees, the Employee class has two subordinate classes for the two types—the FullTime class for full-time employees and the PartTime class for part-time employees.
Within an inheritance hierarchy, lower classes inherit upper classes’ members. Thus, the Employee and Customer classes inherit name from the Person class. Likewise, the FullTime and PartTime
       Plan to instantiate leaves only.
  









































































   512   513   514   515   516