Inheritance uses the idea of reusability or genericity. A programmer creates an object that is general in nature and adds to it after it has been added to another object. This new object is more specific and can be inherited by other objects. Figure 1 shows how inheritance works. The object at the top is the generic type. The objects become more specific as they move down with the most specific objects on the bottom.
Ada 95 is a language which has single inheritance. Table 1 shows the comparison of Java, C++, and Ada 95. Even though Ada 95 is a single inheritance language, programs can be written to support multiple inheritance.
Most object-oriented languages have single inheritance. C++ and Eiffel are exceptions and support multiple inheritance.
At the time this was written, information
in Table 1 could be found at http://www.adahome.com/Resources/Languages/.
| Java | C++ | Ada 95 | |
|---|---|---|---|
| Inheritance | Single
(but with multiple sub typing) |
Multiple | Single
(but supports MI) |
| Separate
Interface/Implementation |
No
(interface generated from code) |
Yes
(header files) |
Yes
(specifications) |
| Garbage Collection | Yes | No | No** |
| Operator Overloading | No | Yes | Yes |
| Generics | No
(but extensive polymorphism) |
Yes
("templates") |
Yes |
| Exceptions | Yes | Yes | Yes |
| Native Multi-threading | Yes | No | Yes |
Figure 1 Inheritance diagram
In Ada 95 inheritance is accomplished
with the help of expandable types. Expandable types are also known
as tagged types because they contain a hidden tag. If an object is
not tagged it can not be inherited. Figure 2 shows how an object
is tagged in Ada 95.
|
type Animal is tagged record Name : string (1..30); end record; |
Figure 3 is an example of what Ada
95 code looks like for a series of objects inheriting from each other.
|
type Animal is tagged record Name : String (1..30); end record; type Mammal is new Animal with
type Dog is new Mammal with
type German_Shepherd is new Dog with
|
In figure 3 Animal is the parent type
to Mammal and Mammal is the child type to Animal. We can also say
that Mammal is derived from Animal. This can be carried on down the
chain as Dog is derived from Mammal and German_Shepherd is derived from
Dog.
Go to Polymorphism or the Table of Contents