473,383 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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.
Jul 22 '05 #1
2 1092
jeffc wrote:
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
Jul 22 '05 #2

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:xk****************@newsread1.dllstx09.us.to.v erio.net...

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.
class Custom : public MiddleLayer {
ThirdParty m_thirdparty;
...
};


That sounds like a possibility - I'll think more about it. Thanks.
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Morgan Cheng | last post by:
It seems no pattern defined by GoF takes advantage of multiple inheritance. I am wondering if there is a situation where multiple inheritance is a necessary solution. When coding in C++, should...
30
by: Vla | last post by:
why did the designers of c++ think it would be more useful than it turned out to be?
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
29
by: MAHESH MANDHARE | last post by:
Hi , Can Anyone explain me exactly why multiple inheritance not used in java and c# thanks, Mahesh -- Have A Good Day, Mahesh, Maheshmandhare@yahoo.co.in
47
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
60
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
5
by: colint | last post by:
Hi I'm fairly new to c++ and I have a question regarding inheritance. I'm trying to create a class based on 2 inherited classes, e.g. class A { ... } class B: public A
3
by: Jess | last post by:
Hello, I've been reading Effective C++ about multiple inheritance, but I still have a few questions. Can someone give me some help please? First, it is said that if virtual inheritance is...
47
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever...
2
by: Immortal Nephi | last post by:
You may have heard diamond shape. You create one base class. One base class has member functions and member variables. You create two derived classes. All member functions and member variables...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.