Genericity versus inheritance
The material that follows, and its appearance in an appendix, deserve some background
explanation. Part of the original impetus for the work that eventually led to this book was
a study that I performed in 1984; in preparation for a graduate course that I was to teach
advanced concepts in programming languages
”, I compared the “horizontal” module
extension mechanism of genericity, illustrated by Ada, Z, LPG and other generic
languages, with the “vertical” mechanism of inheritance introduced by Simula: how these
techniques differ, to what extent they compete, and to what extent they complement each
other. This led to an article on “Genericity versus Inheritance”
, presented at the
first OOPSLA conference, and to a chapter in the first edition of the present book.
When preparing this new edition I felt that both genericity and inheritance were now
understood well enough, and their treatment detailed enough in the rest of the book, to
make the chapter appear too specialized: useful mostly to readers interested in issues of
language design or O-O theory. So I removed it. But then I found out that a regular flow
of articles in the software press still showed must puzzlement over the issue, especially in
the context of C++ for which many people seem to be searching for general guidelines on
when to use “templates” and when to use inheritance. This means the discussion still has
its place in a general presentation of object technology, although it is perhaps best severed
from the main part of the text. Hence this appendix.
The topics reviewed are, in order: genericity; inheritance; how to emulate each of
these mechanisms through the other; and, as a conclusion, how best to reconcile them.
If you have read carefully the remainder of this book, you will find the beginning of
this discussion familiar since we must restart with the basics to get a full picture of each
mechanism, of its contribution, and of its limitations. As we probe deeper and deeper,
perhaps stepping briefly into a few dead ends along the way, the ideal combination of
genericity and inheritance will progressively unfold before our eyes, imposing itself in the
end as almost inevitable and letting us understand, in full detail, the fascinating
relationship between the two principal methods for making software modules open to
variation and adaptation.