Class Refinement

Class Refinement

Classes can be refined through inheritance, which is code reuse. The common members of related classes can be extracted and placed in a base class. Child classes inherit and refine a base class. A personnel application might have SalariedEmployee, HourlyEmployee, and CommissionedEmployee classes that inherit the Employee class. The Employee class holds the common members of all Employee-derived classes. Each derived class adds members to refine the base class. Optionally, derived classes can override members of the base class. Sealed classes cannot be inherited. Inheritance and polymorphism are closely related. Polymorphism calls the correct method at run time from a base reference to a derived object, and it can add considerable efficiencies to an application.

Inheritance and polymorphism and other strategies to refine class usage are reviewed in Chapter 3.