Case Study: Three-Level Inheritance Hierarchy

Three level point/circle/cylinder hierarchy Derive class Cylinder from class Circle4. Class Cylinder should redefine member functions getArea and print member functions. Figs. 4.26-4.27 present class Cylinder, which inherits from class Circle4.
Figure 4.26: Cylinder class header file.
\includegraphics[scale=0.43]{figures/img9.59.ps}
\includegraphics[scale=0.43]{figures/img9.60.ps}
Figure 4.27: Cylinder class inherits from class Circle4 and redefines member function getArea.
\includegraphics[scale=0.43]{figures/img9.61.ps}
\includegraphics[scale=0.43]{figures/img9.62.ps}
Figure 4.28: Point/Circle/Cylinder hierarchy test program. (part 1 of 2)
\includegraphics[scale=0.43]{figures/img9.63.ps}
\includegraphics[scale=0.43]{figures/img9.64.ps}
Figure 4.29: Point/Circle/Cylinder hierarchy test program. (part 2 of 2)
\includegraphics[scale=0.43]{figures/img9.65.ps}
We were able to develop classes Circle4 and Cylinder much more quickly by using inheritance than if we had developed these classes "from scratch". Inheritance avoids duplicating code and the associated code-maintenance problems.












2004-07-29