473,394 Members | 1,701 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,394 software developers and data experts.

Another composition

fog
class A has its children/derived classes B and C. class D is supposed to be
contained inside both B and C.

Is the code right for the above requirement?
class A
{
D d;
};

class B : public A;
class C : public A;

Now should all public and protected members in D be accessible to all
members of B and C?
Is this a good design?
Thanks for your help!

Jul 22 '05 #1
3 936
"fog" <fo*@turboweb.com> wrote
class A has its children/derived classes B and C. class D is supposed to be
contained inside both B and C.

Is the code right for the above requirement?
class A
{
D d;
};

class B : public A;
class C : public A;

Now should all public and protected members in D be accessible to all
members of B and C?
Is this a good design?


Good design limits the visibility of the internals of a class as much as
possible, even to its descendents. Therefore, no, exposing the internals of A
would not be good design.

Claudio Puviani
Jul 22 '05 #2

"fog" <fo*@turboweb.com> wrote in message
news:LG*******************@bgtnsc05-news.ops.worldnet.att.net...
class A has its children/derived classes B and C. class D is supposed to be contained inside both B and C.

Is the code right for the above requirement?
class A
{
D d;
};

class B : public A;
class C : public A;
Seems OK to me.

Now should all public and protected members in D be accessible to all
members of B and C?
No they shouldn't. There's no inheritance of B from D or of C from D, so
there is no automatic access to D's members from B or C.
Is this a good design?


That depends entirely on what you are trying to do. Good design doesn't
exist in the abstract.

john
Jul 22 '05 #3
> class A has its children/derived classes B and C. class D is supposed to be
contained inside both B and C.

Is the code right for the above requirement?
class A
{
D d;
};

class B : public A;
class C : public A;

Now should all public and protected members in D be accessible to all
members of B and C?
Is this a good design?
Thanks for your help!


Seeing that d is declared in the private block of A neither B nor C
has access to it.
Jul 22 '05 #4

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

Similar topics

4
by: fog | last post by:
Given: class A; and B "has-a" A. The composition relationship between A and B can be implemented in three ways: =================== # 1. class B {
7
by: preetam | last post by:
Hi, This question is more towards design than towards c++ details. By looking at books on design patterns and various google threads on the same topic, I see that composition is favoured to...
9
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...
188
by: christopher diggins | last post by:
I have posted a C# critique at http://www.heron-language.com/c-sharp-critique.html. To summarize I bring up the following issues : - unsafe code - attributes - garbage collection -...
4
by: Frederik Vanderhaegen | last post by:
Hi, Can anyone explain me the difference between aggregation and composition? I know that they both are "whole-part" relationships and that composition parts are destroyed when the composition...
1
by: tony | last post by:
Hello! I access the class MyComparer in this way. steel_post.Sort(new MeltPracDataComposition.Composition.MyComparer()); You can see the class definition for MyComparer below. As you can see...
2
by: Gary Wessle | last post by:
Hi what is the difference "in code writing" between aggregation and composition? is the following correct? aggregation (life time of both objects are independent). class A{ /* ... */ };...
3
by: jyck91 | last post by:
I want to get some ideas to organise a composition analyzer?? eg. frequencies of letters Thx for your suggestion
5
by: jyck91 | last post by:
Can anyone give me some ideas to organise a composition analyzer in C? It analyses an english composition. What functions should it include? eg. frequency of letter/ words thanks for help
4
by: Kay Schluehr | last post by:
As you know, there is no operator for function composition in Python. When you have two functions F and G and want to express the composition F o G you have to create a new closure lambda...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
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...
0
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...
0
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...

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.