Re: Passing derived class object array in place of base class object array

From: justanotherguy (justanotherguy63_at_yahoo.com)
Date: 12/03/04


Date: 3 Dec 2004 13:39:25 -0800

Thanks guys for your views. There were some very interesting and
innovative ways to work around the problem in the replies.Sorry for
getting back late because I had a bout of asthma and c++ was far from
my mind for the past few days.

Anyways, I did some soul searching about the design of the application
and the one point that came to my mind was what one friend of mine
used to say: "If it is too hard then maybe that is not the way it
should be". The problem was that there were two parallel hierachies of
classes(no, I did not design this part and I graciously inherited as a
part of legacy code) with one hierachy of classes containing an array
of other appropriate classes. To make this a little clearer,

A<----B<----C<-----D and A is the pure abstract base class.

Now we have

E<----F<----G<----H and F,G,H have arrays of objects of kinds B,C and
D and E is of course the abstract base class.

Now, F,G,H return the arrays they contain to another function that
performs some calculation on it. So, they have to be of the kind A to
be generic and that is where the problem arises.

Here is my take on it: The parallel hierachy idea is not so great coz:
a) We are breaking the encapsulation principle. From what little
domain knowledge I have of the application, B,C and D have too much
coupling between them to be seperate classes.
b) There is some fault in the relationships between the huge number
classes I have and I have to figure that out.
c)To make the classes more cohesive, we have to bring in B,C and D as
data members of F,G and H(which can be done). This probably means that
B,C, and D were not probably that unique to be classes in the fist
place.

Am I talking sense or am I advertersing my ignorance? I find it a
little amusing that in IT, the fault of design is always with the
other guy. I try to manage my ego and not to do that. In this case, it
appears to be the case.

And I believe in the concepts of object orientation as "guidelines"
and not gospel and so will not hesistate to throw it out of the window
if there are tangible benefits. In this case though, it appears as if
the "guidelines" deserve more respect.

What say people?

Your responses will be gretly appreciated.

Cheers,
justanotherguy

alfps@start.no (Alf P. Steinbach) wrote in message news:<41b074b6.2730594484@news.individual.net>...
> * Andrew Koenig:
> >
> > In general, a container of derived objects cannot substitute for a
> > container of base objects, because what happens if you try to put a base
> > object into the container?
>
> Is there any way in C++ to create a smartpointer that acts like a Java
> reference?
>
> Assuming there isn't (which is what I believe), is there any way the
> language could be, er, "improved", so that that would be possible?



Relevant Pages

  • Re: Passing derived class object array in place of base class object array
    ... I did some soul searching about the design of the application ... The problem was that there were two parallel hierachies of ... And I believe in the concepts of object orientation as "guidelines" ... >> container of base objects, because what happens if you try to put a base ...
    (comp.lang.cpp)
  • Re: How to set Site for Control?
    ... > collection of all controls in the design surface. ... > container and its components. ... > there is a separate link object that implements the ISite interface. ... Forms and user control has a member ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Limiting content width - DIV or BODY?
    ... I essentially designed my site for 800x600 px screensize and up, ... I've checked out some award-winning websites and this is technique seems ... So the absolute positioning is only relative to the container not ... the definition of good design simply becomes any website ...
    (alt.html)
  • Re: Windows Ada database support.
    ... >: Why should I query? ... a container that refers to my object. ... = bad design, if you are you talking about changes unknown during design. ...
    (comp.lang.ada)