Kay A. Pentecost propagated the following meme:
> I understand how implementation inheritance works in other languages... but
> so far I don't see if or why VB's lacking it is so bad, because I'm still
> ignorant of a lot of OO things...
>
> I'd like to hear comments on either side... anyone have any?
(Note: I'm a Java hacker mostly, this is written from that prejudice. I'd
be especially interested in the point-of-view of someone who commonly uses
an object-system like CLOS, which uses generic functions instead of
message-passing)
Interface inheritance is the most important kind of inheritance. It's the
cornerstone of Polymorphism - the idea that objects can be treated alike
because they respond to the same messages.
Implementation inheritance is a convenient shortcut. It's saying "because
I'm inheriting the interface of my parent, it's most likely I want to
behave in mostly the same way, so I'll respond _the same way_ to these
messages unless I'm specifically told otherwise."
Implementation inheritance is convenient, but it comes with a number of
important shortcomings that you have to keep in mind. It is far less
flexible than pure interface inheritance, and it often ties you to the
details of your superclass's implementation, breaking encapsulation.
The other problem is that in most languages[1], an interface implies, but
_can not enforce_ a set of contracts that the class is expected to
obey. If you inherit an interface, your class is expected to be able to
polymorphically substitute for its superclass, so it needs to obey the
same contracts as its superclass. A subclass should be a _specialisation_
of the superclass, its behaviour a subset of the superclass's behaviour.
If that is not true, you shouldn't be inheriting its interface.
Sometimes, I think that it was a mistake to join implementation and
interface inheritance as closely as has been done. That said,
implementation inheritance has its place. It's not essential for OO,
but it does save a lot of typing (and duplication) in common cases.
Charles Miller
[1] i.e. those without built in design-by-contract
--
Contributing to the Heat Death of the Universe since 1975.
http://fishbowl.pastiche.org -- -- The Weblog