| Home | Previous Lesson: Base Classes Next Lesson: Inheriting the Interface |
You can design class hierarchies just for code reuse or for sharing the interface or a mix of these two. In this section let's examine inheritance for code reuse.
Let's consider a program for designing data entry forms, where user fills out fields on the screen. The data entry forms may be for different purposes, i.e., entering a record in the inventory master, or entering a transaction into a transaction file, or for a purchase order. Note that, all these forms share functionality, such as, querying the form, printing the form. As a result, you can implement this functionality in the base class. You can save yourself the effort and as well as reduce the size of the program by defining a base class called data-entry-form that implements the above mentioned common functionality. Such a class hierarchy also reduces the effort required to fix bugs or add features, since the changes have to be done in one place only.
A class hierarchy, designed for code sharing has most of its code in the base class (near the top of the hierarchy). This way the code can be reused in many classes. The derived classes represent the specialized classes, i.e., extend the base class's functionality.
| Home | Previous Lesson: Base Classes Next Lesson: Inheriting the Interface |