I’ve been teaching OOP and was trying to convey to my students the important difference between inheritance and the creation of a subtype relation between two types. For example, in C++, I could use private inheritance to ensure that nobody outside sees the subtyping relation.
However, while I can think of a lot of situations where I wouldn’t want to create a subtyping relation (e.g., implementing a Stack via a doubly-linked list class), I can’t really think of good design examples where I would actually choose to follow inheritance without creating a public subtying relation (rather than, say, use aggregation).
Any ideas of good examples?
As a Python programmer, let me say that these are matters that are way, way too subtle. They appear to be purely C++-isms.
In Python, we have inheritance, which creates proper subtypes.
And we have composition using simple attributes, or of the available collections.
This business of private inheritance being a kind of composition seems to be simply confusing. And largely useless.
The C++ examples show private inheritance to create composition with a common interface. In Java, we’d have a common interface. In Python, we have duck typing and don’t need the formalisms.
I don’t think there are good examples — I think the concept is too subtle to be of any real value.