Class Refinement

For a group of related classes, you can refactor the common code into a base class. The base class can then be inherited into one or more specific (derived) classes where the code is reused. Derived classes also are called descendants or child classes. Inheritance implies code reuse. The child classes then can extend (refine) the base class. A personnel application might have SalariedEmployee, HourlyEmployee, and CommissionedEmployee classes that inherit from the Employee class. The Employee class contains the common members of the Employee related classes. Each derived class adds methods or fields to extend and refine the base class. Inheritance and polymorphism are closely related. Polymorphism calls the correct method at run time from a base reference to a derived object. Delaying method binding to run time can provide needed flexibility. This can also add efficiencies and code clarity to an application.

Inheritance and polymorphism are discussed in the next chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.43.36