Topic: C++ and inheritence, moving blobs of trees around.
Author: ldh@cs.brown.edu (Laurent Hasson)
Date: Fri, 10 Sep 1993 23:06:46 GMT Raw View
Now, 2 things.....
You have a set of classes.....
A
B1 _/ \_ B2
/ \ / \
C1 C2 D1 D2
Ok the problem is simple....
I declare an instance of C1, use it, and because of some reason, i
don't need C1 anymore and would like to have a C2 instead. The way to
do it would be to instanciate C2, have a sort of copy operator that
could copy the B1 and A parts of C1 into the newly created C2. And
then destroy the C1. Of course, that can be long for complex objects.
The exemple above is just a bad simple example to illustrate the idea.
Now, why not have a sort of way to just delete a part of a hierarchy
and replace it with another part, keeping just what's in common.
I encountered this kind of problem this summer using the Visual C++ to
do MS windows apps. The problem i had was that i had several ways of
viewing the data being manipulated, and i had a whole hierarchy of
views, isolating all the features and aspects as best i could. The way
i did it was to have a sort of copy operator, and then have a kind of
reservoir of objects. I picked up the good one, did the copy (virtual
operations) and then returned the desired object.
by tree looked like:
...
...
.|.
A
B1 _/ \_ B2
/ \ |
C1 C2 |- D1
|- D2
|- D3
....
|- Dn-1
|- Dn
That was fast, and since my objects were not very big and that i
needed a few only available, it did not take much room... BUT... the
idea seems to me like an interesting one.
Your opinions ????
LDH
PS: I hope i have been clear, more or less.