Re: Explain Why Polymorphism Can't Be Used?
On May 2, 5:59 pm, "Phlip" <phlip2...@gmail.com> wrote:
[...]
- if you derive even hundreds of classes, you have a major design
issue. Abstracting the right thing (into delegation, metadata, or
_something_) might free up your concrete classes
In general, I totally agree with you, but there are exceptions.
I have one very simple interface (just one virtual function)
used to translate input data to UTF-8. There's one derived
class for each input encoding, and there have been literally
hundreds of different character encodings. (At present, I only
support about twenty, but I know of quite a few that I don't
support, and I'm pretty sure that there are even more that I
don't support.)
[...]
- prefer references to pointers. Think in terms of referring to the
base class, not pointing to it. Pointers are more wild and
dangerous than references
Yes and no. References don't support pointer arithmetic, so one
of the worst features of pointers has been eliminated. But it's
still far too easy to end up with dangling references. In cases
where smart pointers are appropriate, in fact, you should
probably avoid references in favor of the smart pointer.
--
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