473,760 Members | 8,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Relationship between multiple diamonds

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 both derived classes.
You need to create fourth derived class. Fourth derived class is
derived from both (two) derived classes. All four classes look like
diamond shape. It does the same what IOS looks like.

What happen if you want multiple diamonds? You can create two
diamonds. Then another class is dervied from both diamonds. You do
too many derived classes as long as more diamonds are related together
and very complex.

Finally, the last bottom class is derived from multiple diamond
classes. All member functions and member variables from the top base
class are inherited down to the last bottom class through multiple
diamonds.

What happen to a large vtable in the bottom class?. A large vtable
contains hundreds or thousands of member functions and hundreds of
member variables. You may want to define one pointer to member
function variable. Then pointer to member function variable can be
called to access thousands of member functions.

According to my test, only single pointer to member function variable
with thousands of member functions are much faster than sub-member
functions. Let's say that each main member functions (total 256 main
member functions) have 16 sub-member functions. Combined with main
member functions and sub-member functions are slow because it requires
extra overhead CPU time. Only single main member functons (total
4,096 main member functions) are faster.

Please let me know what you think about multiple diamonds. You know
what my writing means, but I do not need to provide sample source
code. It is easier to understand my post.

Nephi
Nov 7 '08 #1
2 2097
On Nov 6, 9:59 pm, Immortal Nephi <Immortal_Ne... @hotmail.comwro te:
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 both derived classes.
You need to create fourth derived class. Fourth derived class is
derived from both (two) derived classes. All four classes look like
diamond shape. It does the same what IOS looks like.

What happen if you want multiple diamonds? You can create two
diamonds. Then another class is dervied from both diamonds. You do
too many derived classes as long as more diamonds are related together
and very complex.

Finally, the last bottom class is derived from multiple diamond
classes. All member functions and member variables from the top base
class are inherited down to the last bottom class through multiple
diamonds.

What happen to a large vtable in the bottom class?. A large vtable
contains hundreds or thousands of member functions and hundreds of
member variables. You may want to define one pointer to member
function variable. Then pointer to member function variable can be
called to access thousands of member functions.

According to my test, only single pointer to member function variable
with thousands of member functions are much faster than sub-member
functions. Let's say that each main member functions (total 256 main
member functions) have 16 sub-member functions. Combined with main
member functions and sub-member functions are slow because it requires
extra overhead CPU time. Only single main member functons (total
4,096 main member functions) are faster.

Please let me know what you think about multiple diamonds. You know
what my writing means, but I do not need to provide sample source
code. It is easier to understand my post.

Nephi
I fail to see your point. A diamond shaped inheritance scheme like

istream
/ \
ios_base - ios iostream
\ /
ostream

fits the bill since istream and ostream provide facilities to other
sections of the hierarchy (ifstream, istringstream and ofstream,
ostringstream respectively), iostream is but one of them. You describe
a design where the various corners of the diamonds are meant to serve
nothing but the final derived class.

A class with 256 member functions is grossly overburdened. And you
suggested 4096 member functions? If speed is such a concern, why store
pointers to member functions in the first place? Are you using
inheritance where you should be using composition?

The main reason why one should use inheritance hierarchies is for
reusability, maintainability and flexibility. Keep it simple. If your
idea is to write a complex program with 100K lines using one class and
4096 functions, then do it at your own peril. If thats your idea of
gaining speed, then i'll counter with 'buggy programs' don't run very
well at all. Without classes you lose type-checking. A few weeks after
you implement the design you'll find you can't even maintain it let
alone explain it. You'll do one tiny modification and the ship sinks.
You'll need 20 days instead of 20 minutes to add a tiny feature.
Customers don't like that.
Nov 7 '08 #2
On Nov 7, 1:51*am, Salt_Peter <pj_h...@yahoo. comwrote:
On Nov 6, 9:59 pm, Immortal Nephi <Immortal_Ne... @hotmail.comwro te:


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 both derived classes.
You need to create fourth derived class. *Fourth derived class is
derived from both (two) derived classes. *All four classes look like
diamond shape. *It does the same what IOS looks like.
What happen if you want multiple diamonds? *You can create two
diamonds. *Then another class is dervied from both diamonds. *You do
too many derived classes as long as more diamonds are related together
and very complex.
Finally, the last bottom class is derived from multiple diamond
classes. *All member functions and member variables from the top base
class are inherited down to the last bottom class through multiple
diamonds.
What happen to a large vtable in the bottom class?. *A large vtable
contains hundreds or thousands of member functions and hundreds of
member variables. *You may want to define one pointer to member
function variable. *Then pointer to member function variable can be
called to access thousands of member functions.
According to my test, only single pointer to member function variable
with thousands of member functions are much faster than sub-member
functions. *Let's say that each main member functions (total 256 main
member functions) have 16 sub-member functions. *Combined with main
member functions and sub-member functions are slow because it requires
extra overhead CPU time. *Only single main member functons (total
4,096 main member functions) are faster.
Please let me know what you think about multiple diamonds. *You know
what my writing means, but I do not need to provide sample source
code. *It is easier to understand my post.
Nephi

I fail to see your point. A diamond shaped inheritance scheme like

* * * * * * * * *istream
* * * * * * * */ * * * * \
ios_base - ios * * * * * * iostream
* * * * * * * *\ * * * * /
* * * * * * * * *ostream
You are right. I guess that you understand.
fits the bill since istream and ostream provide facilities to other
sections of the hierarchy (ifstream, istringstream and ofstream,
ostringstream respectively), iostream is but one of them. You describe
a design where the various corners of the diamonds are meant to serve
nothing but the final derived class.
Let me show you an example of multiple diamonds scheme. You will see
more than two inheritance.

A E M Q
/ \ / \ / \ / \
B C F G N O R S
\ / \ / \ / \ /
D H P T
\ / \ /
\ / \ /
\ / \ /
I U
/ \ / \
J K V W
\ / \ /
L X
\ /
\ /
\ /
\ /
\ /
\ /
\ /
Y

If you add virtual to each derived class like this "virtutal public
A...Y" You will be able to share and modify member variables in base
class when you invoke to call derived class' member function.
A class with 256 member functions is grossly overburdened. And you
suggested 4096 member functions? If speed is such a concern, why store
pointers to member functions in the first place? Are you using
inheritance where you should be using composition?
No, it is not composition. I talk about multiple diamond
inheritance. You always define "pointer to member function" variable
in the bottom of derived "class Y". You can see that each derived
class inherits member functions down to the bottom from the top. Each
derived class can have 10-100 member functions.

You can see that class Y receives all member functions from all
derived classes through inheritance. You can invoke to call pointer
to member function variable in the class Y before member function in
one of these derived class is in turn to be called.

You can have 4,096 or 32,768 or more member functions when your
project is getting too large. Each member function's memory address
is stored in a large vtable pointer.
The main reason why one should use inheritance hierarchies is for
reusability, maintainability and flexibility. Keep it simple. If your
idea is to write a complex program with 100K lines using one class and
4096 functions, then do it at your own peril. If thats your idea of
gaining speed, then i'll counter with 'buggy programs' don't run very
well at all. Without classes you lose type-checking. A few weeks after
you implement the design you'll find you can't even maintain it let
alone explain it. You'll do one tiny modification and the ship sinks.
You'll need 20 days instead of 20 minutes to add a tiny feature.
Customers don't like that.- Hide quoted text -
You are referring global variables and global functions, but you can
still use class when you declare static to both member variables and
member functions. You don't need type-checking unless your source
code is very simple when your writing code is very careful to be
tested without bugs.

You add too many derived classes. They gain more pounds. The ship is
too heavy with tons of derived classes before it sinks because of
overweight. How can you do maintainability ?

Nephi
Nov 7 '08 #3

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

Similar topics

9
2314
by: Code4u | last post by:
My colleagues and I have been discussing techniques for implementing interfaces in C++. We're looking for a mechanism similar to COM's QueryInterface, in which a certain types of objects can be queried, at run-time, for a particular interface and if it is supported, a pointer or reference to that interface passed to the caller. Two possible implementations came up, multiple inheritance and composition. Using MI the class multiply inherits...
2
10652
by: suzanne shelton | last post by:
Help! I have two tables that i am wishing to join that involve a multiple field primary key on the primary table. Primary table: ScheduleHistory SID *PK Schedule *PK Secondary table: Transactions SID Schedule ...
4
9501
by: JSMiami | last post by:
I have a form that is fed by a certain table. This table connects to an intermeddiate table and then a look up table. All of this is done to accomplish a many-to-many relationship. Imagine that the form's table represents employees in a company and let's assume that an employee can belong to multiple departments. The lookup table mentioned above is represents the departments and the intermediate table represents the many-to-many...
8
2211
by: Gaetan | last post by:
hi i have 2 classes A1 and A2 implementing a problem with 2 different ways i also have 2 other classes X1 and X2 implementing an other problem i need classes that provide A1+X1 methods, A1+X2, A2+X1 and A2+X2: interface A class A1 implements A
60
4932
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
1
1282
by: crazdandconfusd | last post by:
I have a database with two tables I use for shipping information. One is for if I'm only shipping one item and the other is for a back page of a report for when I ship multiple items. If I'm shipping multiple items, I put SEE REVERSE in the single item block and then enter the rest in a subform linked to the multiple item table. I'm trying to generate a report that lists all items shipped using a tracking number, but when I create a query, I...
2
2700
by: rsteph | last post by:
I took a number of classes back in college with Java, VB, and VB.NET, and a few in C++. I was looking through some of my books the other day and decided to brush up on my C++ programming, as I'd like to get back into writing programs. I went out and bought a book called "Beginning C++ Game Programming" figuring since I like games it might be fun to refresh myself in the syntax in logic in a very basic game programming type format. I'm having...
8
3938
by: cerise | last post by:
I can't figure out how to make and handle multiple stacks and use them so I could create four linked list stacks representing each suit of cards, one stack each for diamonds, hearts, spades, and clubs. I use objects as my cards. I don't know how to make more than one stack. Can anyone help me out? If I'm not being clear, I'll be happy to clarify the problem I have. here is the class I used to make the Objects for cards, public class...
4
1854
by: Phil Stanton | last post by:
Having spent ages sorting out the layout of my relationship window with about 60 tables and getting it all tidy and with enough of the tables visible to show the PK an FK relaionshipsOn a subseqent occassion, on opening the relationship window, I found all the tables had shrunk so that in most cases, only the table names were visible and the fields could only be seen by "expanding" the table again. I know you can print out the relationship...
0
9521
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
10107
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9945
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
9900
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
9765
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...
1
7324
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6599
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();...
0
5214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3442
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.