Support for OOP
- Polymorphism -- inheritance
Inheritance
- dynamic binding
- protection
- multiple inheritance
slide: Support for OOP
Operationally, the power of inheritance comes from
message dispatching.
This mechanism is called dynamic binding.
Message dispatching
takes care of selecting the right method in response
to a message or method call.
In a hierarchy of (derived) classes, a method for an object
may be either defined within the class
of the object itself or by one of the classes from which
that class is (directly or indirectly) derived.
Message dispatching is an essential mechanism for supporting
polymorphism, since it allows to choose the most appropriate
behavior for an object of a given type.
This must occur at runtime, since the type of an object
as determined at compile-time may be too general.
An important issue in determining whether a language
supports object-oriented programming is whether
it offers a protection mechanism to shield
the vulnerable parts of a base class from the classes
that derived from that class.
Another question of interest is whether a language must support
multiple inheritance.
Clearly, there is some disagreement on this issue.
For example, Smalltalk-80 and Java do not support
multiple inheritance.
The Eiffel language, on the other hand, supported
multiple inheritance from its first days.
For C++, multiple inheritance was introduced
at a later stage.
At first, it was thought to be expensive
and not really necessary.
Closer analysis, however, revealed that the cost was not
excessive. (See Ellis and Stroustrup, 1990.)
The issue of multiple inheritance is still not
resolved completely.
Generally, it is acknowledged to be a powerful
and at the same time natural extension of single inheritance.
However, the inheritance mechanism itself seems to be
under attack.
Some doubt remains as to whether inheritance is a suitable
composition mechanism when regarded from the perspective of
reuse and reliability.
An elegant solution is provided by Java which
offers multiple interface inheritance, by allowing
multiple interfaces to be realized by an
actual class.