Book contents
- Frontmatter
- Contents
- Preface
- One Program Design
- Two Data Types
- Three Object-Oriented Programming Concepts
- Four Features of Programming Languages
- Five Object-Oriented Methods
- Six Inheritance and Polymorphism
- Seven OO Data Structures
- Eight Arrays and Matrices
- Nine Advanced Topics
- Appendix A Fortran 90 Overview
- Appendix B Selected Exercise Solutions
- Appendix C Companion C++ Examples
- Bibliography
- Glossary of Object-Oriented Terms
- Index
Six - Inheritance and Polymorphism
Published online by Cambridge University Press: 15 October 2009
- Frontmatter
- Contents
- Preface
- One Program Design
- Two Data Types
- Three Object-Oriented Programming Concepts
- Four Features of Programming Languages
- Five Object-Oriented Methods
- Six Inheritance and Polymorphism
- Seven OO Data Structures
- Eight Arrays and Matrices
- Nine Advanced Topics
- Appendix A Fortran 90 Overview
- Appendix B Selected Exercise Solutions
- Appendix C Companion C++ Examples
- Bibliography
- Glossary of Object-Oriented Terms
- Index
Summary
Introduction
As we saw earlier in our introduction to OOP, inheritance is a mechanism for deriving a new class from an older base class. That is, the base class, sometimes called the super class, is supplemented or selectively altered to create the new derived class. Inheritance provides a powerful code reuse mechanism since a hierarchy of related classes can be created that share the same code. A class can be derived from an existing base class using the module construct illustrated in Figure 6.1.
We note that the inheritance is invoked by the USE statement. Sometimes an inherited entity (attribute or member) needs to be slightly amended for the purposes of the new classes. Thus, at times one may want to bring into the new class selectively only certain entities from the base class. The modifier ONLY in a USE statement allows one to select the desired entities from the base class as illustrated in Figure 6.2. It is also common to develop name conflicts when combining entities from one or more related classes. Thus, a rename modifier, =>, is also provided for a USE statement to allow the programmer to pick a new local name for an entity inherited from the base class. The form for that modifier is given in Figure 6.3.
It is logical to extend any or all of the aforementioned inheritance mechanisms to produce multiple inheritance. Multiple Inheritance allows a derived class to be created by using inheritance from more than a single base class.
- Type
- Chapter
- Information
- Object-Oriented Programming via Fortran 90/95 , pp. 137 - 156Publisher: Cambridge University PressPrint publication year: 2003