4. Working with Classes : Inheritance : Class Relationships : Inheritance Hierarchy (Generalization/Specialization)
 
Share this page                  
Inheritance Hierarchy (Generalization/Specialization)
The inheritance hierarchy inter-class relationship assumes that each class defines its own attributes and methods and inherits those defined for its superclass.
In developing an application for managing a company, you might define a superclass called Employee with two subclasses, PermanentEmployee and TempEmployee. Because every employee must be either permanent or temporary, Employee is an abstract (general) class that defines attributes common to all employees, such as LastName, FirstName, EmpNum, and HireDate. PermanentEmployee and TempEmployee are specialized classes that represent actual employees.
The PermanentEmployee and TempEmployee subclasses inherit the attributes of Employee. In addition to the Employee attributes, PermanentEmployee defines attributes specific to its class, such as InsurancePlan and NextReviewDate.
Because managers are a specific kind of permanent employee, you might define a Manager user class that is a subclass of PermanentEmployee. In addition to the attributes inherited from both of its superclasses, this class also has a BonusRate attribute.
Methods common to all staff are also defined at the top level. The Employee class, for example, defines the Hire and Terminate methods. Methods specific to a subclass are defined at the subclass level. For example, the Manager class might define a CalculateBonus method.
Examples of OpenROAD system classes that follow this relationship model are ActiveField and ButtonField. ActiveField is an abstract class that defines the characteristics and behavior of all fields with which users can interact. The ButtonField class is a subclass of ActiveField that provides an area on the form or which the user can initiate an action. Its characteristics and behavior are more specifically defined than its parents.