Re: avoid inheritance from std::map
On Dec 17, 12:17 am, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
James Kanze wrote:
[...]
template < typename T >
void reverse ( std::vector<T> & vec );
then you have to answer the question whether it should
match a word or not. Depending on the answer, inheritance
may or may not be the more correct way to go.
Conceptually, it shouldn't. It says it wants an
std::vector<T>. std::vector<T> is not some arbitrary
interface; it's a concrete class.
Yes, that's what the signature of the function says. The
question that one has to answer with regard to the type 'word'
is precisely whether a word _is_ a vector or not.
The standards committee has already defined what is or is not a
vector. If you add or remove functionality (or even if you
change the name), it is not an std::vector.
(Maybe. I'm really just speculating here. But I do believe
that the author of the class has the responsibility of defining
what that class is, i.e. its contract. What that means exactly,
in a case like this, is open to discussion; suppose I derive
just to provide a convenience constructor. Is the result an
std::vector or not?)
Your contention that it never is (conceptually) just
presupposes an answer that IMO cannot be given without knowing
more about the code base and the problem at hand.
Yes. The question is Socratic: designed to stimulate thought,
rather than have a concrete or precise answer.
Practically, of course, design is often the art of
compromize, and rather than write a completely new function,
one might prefer inheritance for that reason as well.
That, too.
(I'm not really sure that "conceptually" is the word I'm
looking for here. I mean something that is really pure and
abstract, independently of any practical considerations.)
In my experience, something like that does not exist in
programming :-)
That's because you're a software engineer, and not a (pure)
computer scientist:-).
(In practice, of course, I can definitely think of cases where
I'd derive publicly from std::vector. My question is just to
what degree such derivation is a pragmatic compromise, rather
than something conform to some possibly overidealist theory.
Mental masturbation, I know.)
--
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