473,718 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1105
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.********@com Acast.net> wrote in message
news:xk******** ********@newsre ad1.dllstx09.us .to.verio.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
2180
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 multiple inheritance still be avoided? If yes, why multiple inheritance is introducted into C++?
30
2721
by: Vla | last post by:
why did the designers of c++ think it would be more useful than it turned out to be?
22
23376
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 examples?
29
4658
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
3636
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
60
4924
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 'target' programming community herein) to get some community input and verify (or not) the following two statements. Few programmers (3 to7%) UNDERSTAND 'Strategic Functional Migration
5
2751
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
2553
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 used, then "the responsibility for initializing a virtual base is borne by the most derived class in the hierarchy". What does it mean? Initializing base class is usually done automatically by the compiler, but a derived class can invoke the base...
47
4019
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 support multiple inheritance. In C++ for instance I noticed that the compiler flags an error if you use the "ref" keyword on a class with multiple base classes. This supports the above quote. However, under the "CodeClass2.Bases" property (part...
2
2093
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 from one base class are inherited into two derived classes. You want both derived classes to share member variables of the one base class. You can do this way so you don't need keyword -- friend. You can add virtual public One_Base_Class on...
0
8827
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8722
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9206
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9118
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9052
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7985
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5971
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3180
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2122
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.