Basic OOP in Ada 95


Need - Increased Support for OOT


Previous slide Contents Next slide


From the Script: Slide 21 - Basic OOP in Ada 95

Ada 95 continues the strong inherent ability of Ada 83 to support abstraction and modularity. The addition of support for child libraries and enhancements to Ada's OO model provides excellent support for data and algorithm abstraction. It also supports the ability to develop very modular applications, while remaining upwardly compatible with Ada 83 developments.

Ada 83 supported a form of inheritance through the use of ‘generic’ packages, and by the implementation of variant records. The use of generics, or procedural templates, was a difficult concept for some early Ada developers. Once mastered however, they provided a very powerful mechanism for procedural abstraction and allowed a rudimentary inheritance of the base structure of the generic package. Variant records could also be used, but many found them to be cumbersome and resulted in a large increase in overhead. Ada 95 uses 'tagged types' to support inheritance and allows the developer to derive child packages directly from the parent, with or without an extension of the structure and the methods of the parent. Ada 95 also supports the ability to create child libraries that can be separately compiled from the parent library, while still deriving the functionality and structure of the parent.

Ada 83 supported a form of polymorphism through the use of overloading that allowed the developer to reuse a procedural name or operator by redefining the context and semantics. For example, when using integer numbers, the + sign adds one integer to another. The + operator could be redefined to work with an abstract data type consisting of a set of colors and provide the proper color mix (i.e., red + yellow = orange). This polymorphic behavior had to be resolved at compile time. Ada 95 supports a true polymorphic operation through the use of class-wide types and type extensions, which can contextually recognize the appropriate operation to perform. In other words, a call to 'ProcessPayroll' will execute the correct code whether it is for a civil servant or military person. Ada 83 only supported static (or early) binding. This meant that all references had to be resolved at compile time in order to successfully create an executable. Ada 95 supports dynamic (or late) binding, which allows the developer to create applications that resolve messaging references during execution based on the actual instances of the objects involved.

Ada 95 does not directly support multiple inheritance because of the language problems that are caused by its use. The general concept of multiple inheritance is that an abstract data type can have multiple (two or more) parents. This concept becomes troublesome if the parents are derived from the same ancestor. The issues are whether the child inherits two copies of the type ancestor (one from each parent), and what happens if the same method is inherited from both parents, which was originally derived from the single ancestor. This scenario causes ambiguity that can lead to some unexpected results. In most cases where multiple inheritance seems to be warranted, there is almost always an inherited type that is clearly the dominant parent. Ada 95 handles this condition by only directly allowing single inheritance, but permitting the use of indirect secondary inheritance [Barnes].