 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
jeffc Guest
|
Posted: Tue Sep 28, 2004 2:47 pm Post subject: Multiple inheritance design question |
|
|
I have the following situation and I'm not sure how to proceed. Currently
we have a class hierarchy that looks like this
class Base
class MiddleLayer : public Base
class Custom : public MiddleLayer
Now we have a third party set of classes that we need to integrate. I
consider this a "mix in" type of situation, where we just need that
behavior, but we can't alter the code (we don't have the source).
class ThirdParty : public Base
So the first idea off the top of my head is
class Custom : public MiddleLayer, public ThirdParty
The problem of course the lack of a virtual base class. What we really want
is
class MiddleLayer : virtual public Base
class ThirdParty : virtual public Base
But then we'd have to change the third party "source" code. I put "source"
in quotes because most people think of source code as the cpp file, while
they do send us the hpp header files (of course), and technically we could
change them. But I don't think that would be a very good idea. Any ideas
here? By the way, this is the first time this particular third party code
has been used in an actual production environment, so they might not have
thought fully through the problem, I'm not sure.
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Tue Sep 28, 2004 3:21 pm Post subject: Re: Multiple inheritance design question |
|
|
jeffc wrote:
| Quote: | I have the following situation and I'm not sure how to proceed. Currently
we have a class hierarchy that looks like this
class Base
class MiddleLayer : public Base
class Custom : public MiddleLayer
Now we have a third party set of classes that we need to integrate. I
consider this a "mix in" type of situation, where we just need that
behavior, but we can't alter the code (we don't have the source).
class ThirdParty : public Base
So the first idea off the top of my head is
class Custom : public MiddleLayer, public ThirdParty
The problem of course the lack of a virtual base class. What we really want
is
class MiddleLayer : virtual public Base
class ThirdParty : virtual public Base
But then we'd have to change the third party "source" code. I put "source"
in quotes because most people think of source code as the cpp file, while
they do send us the hpp header files (of course), and technically we could
change them. But I don't think that would be a very good idea. Any ideas
here? By the way, this is the first time this particular third party code
has been used in an actual production environment, so they might not have
thought fully through the problem, I'm not sure.
|
Without knowing more detail on what 'MiddleLayer' does and what the
ThirdParty class is for and why they need to be mixed in, I can only
suggest:
class Custom : public MiddleLayer {
ThirdParty m_thirdparty;
...
};
or
class Custom : public ThirdParty {
MiddleLayer m_middlelayer;
...
};
Yes, you will get two 'Base' objects, but one will be inherited while
the other hidden inside the data member.
You will need to delegate all the functionality from the non-inherited
class, of course.
Victor
|
|
| Back to top |
|
 |
jeffc Guest
|
Posted: Tue Sep 28, 2004 3:58 pm Post subject: Re: Multiple inheritance design question |
|
|
"Victor Bazarov" <v.Abazarov (AT) comAcast (DOT) net> wrote
| Quote: |
Without knowing more detail on what 'MiddleLayer' does....
|
I don't think it's relevant, but I just included it in case it posed some
problem I hadn't thought of.
| Quote: | class Custom : public MiddleLayer {
ThirdParty m_thirdparty;
...
};
|
That sounds like a possibility - I'll think more about it. Thanks.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|