Re: Design problem with inheritance
- From: "Alvin Ryder" <alvin321@xxxxxxxxxxx>
- Date: 14 Jul 2006 07:36:44 -0700
Dmitry A. Kazakov wrote:
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
Frankly I'm only guessing at what the OP wants, I should've made that
clear. But do you not agree parametric types are useful when you want
the type to vary, as in stack<int> and stack<char>?
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.
And in C++ you /can/ use polymorphism and inheritence in the parametric
type, as in
class Base has virtual operation1()
template <class T> class Derived1 : public Base
template <class T> class Derived2 : public Base
// Then
vector<Base*> vectorX;
vectorX.push_back( new Derived1<int> ); // Now its an int
vectorX.push_back( new Derived2<char>); // Now its a char
// Now call operation1 on each ... its polymorphic.
I'm not sure why you're saying you can't contain polymorphic objects?
Ok I'm probably misunderstanding you as well? Nevermind, I've had a 16
hour day ... I'm going to bed.
-Cheers.
.
- Follow-Ups:
- Re: Design problem with inheritance
- From: Dmitry A. Kazakov
- Re: Design problem with inheritance
- References:
- Design problem with inheritance
- From: srinivasarao_moturu
- Re: Design problem with inheritance
- From: Alvin Ryder
- Re: Design problem with inheritance
- From: Dmitry A. Kazakov
- Design problem with inheritance
- Prev by Date: Re: Persistence
- Next by Date: Re: Persistence
- Previous by thread: Re: Design problem with inheritance
- Next by thread: Re: Design problem with inheritance
- Index(es):
Relevant Pages
|