Re: Design problem with inheritance
- From: "Dmitry A. Kazakov" <mailbox@xxxxxxxxxxxxxxxxx>
- Date: Fri, 14 Jul 2006 09:54:54 +0200
On 13 Jul 2006 14:31:51 -0700, Alvin Ryder wrote:
I would not use inheritence in this way.
1. When you need to vary types use generics or templates if your
language supports them.
Well, because this, IMO wrong, advise has repeated ... no! Generics expose
a static form of polymorphism. This automatically excludes any possibility
to have a container of polymorphic objects. With generics the container
*itself* will be polymorphic, its elements will be not. It seems that the
OP wished a different thing: a non-polymorphic container of polymorphic
elements.
2. Otherwise, if there is an object root, like Java's "Object", you can
cast to Integer and Char from it. I've heard it said "avoid casts" but
that's how Sun did it. C++ libs may or may not have such a root though.
This is the essence of the problem. Only the operations declared on the
class (ABC) are legal. The design decision to make is, whether the views of
ABC as int/string should be in the contract of. H.S. already covered that
in his response.
3. Failing that, back in the C days, we had to use "void *" with casts
to whatever type was required, it worked well.
(:-))
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
.
- Follow-Ups:
- Re: Design problem with inheritance
- From: Alvin Ryder
- Re: Design problem with inheritance
- References:
- Design problem with inheritance
- From: srinivasarao_moturu
- Re: Design problem with inheritance
- From: Alvin Ryder
- Design problem with inheritance
- Prev by Date: Re: Observer pattern limitations
- Next by Date: Re: Observer pattern limitations
- Previous by thread: Re: Design problem with inheritance
- Next by thread: Re: Design problem with inheritance
- Index(es):
Relevant Pages
|