Re: Design problem with inheritance



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
.



Relevant Pages

  • 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: light weight types
    ... The implementer of Container has no idea what type it is, it's just some type, any type. ... Since we don't know what it is, all we can guarantee is that it is an Object of some type (all non-primitive types are a subclass of Object, and generics don't use primitive types), so wherever `T' is found in the implementation, you can mentally replace it with `Object' for the same effect. ... You can also specify a /lower/ bound on the type, by specifying `super' instead of `extends'. ... Remember that a container stores it type: you can store any B into a Container, so being able to cast from Containerto Containermeans you can put a B into the ...
    (comp.lang.java.programmer)
  • Re: Delphi 2007 Language Feature: Generics
    ... | i.e. if Micha knows that a certain level of understanding of generics ... | generics also has the knowledge of the alternatives. ... derived from a base container item class. ... storage manager with any class of contained item. ...
    (borland.public.delphi.non-technical)
  • Short Steps Toward Generic Programming: Introduction
    ... since I have promised to publicize the present crop of Fortran ... more detail) my proposal for generic programming. ... Another form of polymorphism that is simle in another way is called ... similar to the ad-hoc generics. ...
    (comp.lang.fortran)
  • Re: How come Ada isnt more popular?
    ... container varies, the element does not. ... The user should be able to describe string type in language terms ... but there are no generics instantiated. ... Implementation inheritance without values ...
    (comp.lang.ada)