14 - Object Oriented Programming
Published online by Cambridge University Press: 05 July 2014
Summary
We now come to a discussion of the basic features of Ada which support what is generally known as object oriented programming or OOP. Ingredients of OOP include the ability to extend a type with new components and operations, to identify a specific type at run time and to select a particular operation depending on the specific type. A major goal is the reuse of existing reliable software without the need for recompilation.
This chapter concentrates on the fundamental ideas of type extension and polymorphism. Related topics are type parameterization (using discriminants) and genericity; these are discussed in Chapters 18 and 19 respectively. Finally, Chapter 20 considers how these various aspects of OOP all fit together especially with regard to multiple inheritance.
The reader might find it helpful to reread Sections 3.2 and 3.3 before considering this chapter in detail.
Type extension
In Section 12.3 we saw how it was possible to declare a new type as derived from an existing type and how this enabled us to use strong typing to prevent inadvertent mixing of different uses of similar types. We also saw that primitive operations were inherited by the derived type and could be overridden and, moreover, that further primitive operations could be added if the derivation were in a package specification.
We now introduce a more flexible form of derivation where it is possible to add additional components to a record type as well as additional operations.
- Type
- Chapter
- Information
- Programming in Ada 2012 , pp. 301 - 360Publisher: Cambridge University PressPrint publication year: 2014