473,503 Members | 1,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

public inheritance wth advantage and disdvantage

Hello experts!

My question is what advantage and disadvantage have public inheritance.

The answer that I have to this is that sometimes it is an advantage to let a
client have access to everything
declared in the public section of the derived class and the base class and
sometimed it is an disadvantage.
Another important advantage is that wherever you can use an object of base
class you can also use an object of it's derived class which result to using
polymorfism.
Sometimes it's a disadvantage to have the client be able to access everyting
in the public section.
If you use public inheritace and you want to use the methods in the
implementation it's not a good idea
because the client can access them.

Have you any additional advantage or disadvantage to add to those that I
have mentioned.

Many thnaks

//Tony
Aug 16 '05 #1
2 1808
Tony Johansson wrote:
Hello experts!

My question is what advantage and disadvantage have public inheritance.

The answer that I have to this is that sometimes it is an advantage to let a
client have access to everything
declared in the public section of the derived class and the base class and
sometimed it is an disadvantage.
Another important advantage is that wherever you can use an object of base
class you can also use an object of it's derived class which result to using
polymorfism.
Sometimes it's a disadvantage to have the client be able to access everyting
in the public section.
If you use public inheritace and you want to use the methods in the
implementation it's not a good idea
because the client can access them.

Have you any additional advantage or disadvantage to add to those that I
have mentioned.


It's not really about "advantages/disadvantages", they represent different relationships.

If you publicly inherit from a base class then the derived class "is a" type of base class, the base class can be "substituted by" a derived class. The whole point of public
inheritance is polymorphism.

Private inheritance means that the derived class is "implemented in terms of" or composed from the base class.

Have you read sections 19-25:
http://www.parashift.com/c++-faq-lite/

Ben
--
I'm not just a number. To many, I'm known as a String...
Aug 16 '05 #2
Tony Johansson wrote:
My question is what advantage and disadvantage have public inheritance.
It depends on what you consider "advantage" or "disadvantage", doesn't it?
The answer that I have to this is that sometimes it is an advantage to let a
client have access to everything
declared in the public section of the derived class and the base class and
sometimed it is an disadvantage.
Good answer. Does this actually provide any information? It's like when
asked about the climate in Norway, you'd say, "Sometimes it rains and some
other times the sun's shining". No information whatsoever, except that it
doesn't rain all the time.
Another important advantage is that wherever you can use an object of base
class you can also use an object of it's derived class which result to using
polymorfism.
It doesn't necessarily involve polymorphism.
Sometimes it's a disadvantage to have the client be able to access everyting
in the public section.
Like, when?
If you use public inheritace and you want to use the methods in the
implementation it's not a good idea
because the client can access them.
Huh?
Have you any additional advantage or disadvantage to add to those that I
have mentioned.


I think you're thinking too much into that. What's the advantage and
disadvantage of addition? How about division? And multiplication? All
those operations are necessary in certain situations.

Public inheritance exists to specifically model the "is-a" relationship.
An object of the derived class can be used where an object of the base
class is expected. The language provides a conversion between the two.
If you don't want public members of the base class to be accessible via
the derived class object, don't use public inheritance.

V
Aug 16 '05 #3

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

Similar topics

14
6378
by: Axel Straschil | last post by:
Hello! Im working with new (object) classes and normaly call init of ther motherclass with callin super(...), workes fine. No, I've got a case with multiple inherance and want to ask if this...
19
2310
by: qazmlp | last post by:
class base { // other members public: virtual ~base() { } virtual void virtualMethod1()=0 ; virtual void virtualMethod2()=0 ; virtual void virtualMethod3()=0 ;
5
2166
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...
14
12877
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at...
22
23316
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...
15
7170
by: Sinex | last post by:
Hi, Why does C# disallow multiple inheritance? Whats the reason behind this? Is there any advantage or is it just a method to avoid some problems (if so, what problems?) that come with multiple...
14
1543
by: Mark O'Flynn | last post by:
I would like some advice regarding implementing inheritance using vb.net. I have an application written in vb6 that I am rewritting from the ground up in vb.net to take full advantage of .net,...
2
6298
by: Kevin Newman | last post by:
I have been playing around with a couple of ways to add inheritance to a JavaScript singleton pattern. As far as I'm aware, using an anonymous constructor to create a singleton does not allow any...
8
20586
by: weird0 | last post by:
Can anyone explain briefly what is the difference between inheritance and polymorphism? i read and seem to forget it again and again... Can anyone along with good examples of c# explain the...
0
7089
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...
0
7282
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,...
1
6995
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
7463
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...
0
5581
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,...
0
4678
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...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1515
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 ...
1
738
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.