Re: Design problem with inheritance



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.

.



Relevant Pages

  • Re: Design problem with inheritance
    ... When you need to vary types use generics or templates if your ... Generics provide polymorphism for poor. ... template class Derived1: ... I meant that if you have stack generic, then you cannot put different types ...
    (comp.object)
  • Re: Collection of Generic Objects
    ... uses of the term "polymorphism" in different contexts. ... same as Generics, which was not supported at the time the article was ... The difference between subtype polymorphism and parametric polymorphism lies ... implemented the User class code himself, ...
    (microsoft.public.dotnet.framework)
  • Re: .NET 2.0 to be launched on Nov 8
    ... native for generics to work. ... > and probably Delphi for Win32 RSN. ... > do when they compile a template, ...
    (borland.public.delphi.non-technical)
  • Re: .NET 2.0 to be launched on Nov 8
    ... One does delegation out ... >> difference in philosophy between generics and templates. ... do when they compile a template, ...
    (borland.public.delphi.non-technical)
  • Re: Cannot apply indexing with [] to an expression of type with ge
    ... template to make me my function work for both types. ... will work with any type that satisfies the constraints. ... compiler doesn't seem to be able to figure it out. ... think you can provide a constraint, thus using generics is not a good idea. ...
    (microsoft.public.dotnet.languages.csharp)