Re: Warning
On Mar 3, 9:09 pm, Ian Collins <ian-n...@hotmail.com> wrote:
Alf P. Steinbach wrote:
[...]
But on the third and gripping hand, while the opinion that I
think triggered that blast, "don't derive from concrete
classes", may not be the world's best advice, it is a
practice that works for some kinds of problems.
Maybe "avoid deriving publicly form concrete classes" would be
better advice? It certainly applies to standard containers.
I don't know. I haven't seen the thread that goes into that
topic in detail---I rather thought the reaction concerned not
making virtual functions public. But whatever: a fairly long
time ago, Scott Meyers recommended not deriving from concrete
classes, or at least, not deriving from classes with data
members. Because of the problems correctly implementing
assignment, I think. In practice, on the other hand, the
template method pattern will often require derivation from a
class with data members, and it's a fairly well established
pattern. And since we've since more or less learned that
assignment and polymorphism don't mix well, classes using the
template method pattern will normally block assignment, rather
than try to implement it.
At any rate, I don't really think of it as a general rule,
although except when using the template method pattern, it's not
something that you'd probably want to do too often. (Note too
that it's been a while since I've heard anyone argue for this
rule. I don't know what Scott's position concerning it is
today.)
--
James Kanze