Re: Choosing between public and private inheritance
On Apr 17, 3:12 am, "Daniel T." <danie...@earthlink.net> wrote:
In article <xtxFl.1080$b11....@nwrddc02.gnilink.net>,
"Dennis Jones" <djo...@nospam.com> wrote:
[...]
Public inheritance assumes substitutability:
[http://preview.tinyurl.com/w3car]
Not always. At least not for some meanings of "inheritance".
Surely you don't think that every class inheriting from
std::iterator is substitutable.
This is really an issue of whether one is talking about design
or implementation technique. Regretfully, there's no
established vocabulary to make the distinction. I tend to use
"inheritance" for the implementation technique, and "derivation"
for the design concept---in these terms, not all inheritance is
used to implement derivation. But clearly, this distinction is
not in widespread use or well established.
Can a MapTree<Key, T> be use anywhere a GenericTree<T> can be
used? Can you use a MySpecialTree anywhere you are using a
MapTree<int, MySpecialType>?
Are there even functions in your code that pass GenericTree<T> or
MapTree<int, MySpecialType> by reference or pointer?
I tend to use a slightly different vocabulary (although the
results are pretty much the same). If the class I'm deriving
from defines a contract, and my class guarantees to support that
contract, then the inheritance should be public. Otherwise not.
And if the reason I'm inheriting isn't to "derive" (using the
distinction above), other rules hold.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34