472,353 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

structural inheritance bad?

Structural inheritance (inheriting implementation) is equivalent to
composition in that a particular method must either call 'Base::foo' or
invoke 'base.foo'. Apparantly, The Literature tells us to prefer
composition over inheritance. Can anyone provide some reasons why this
is the case (based on "real-world" experience)? For example, is
structural inheritance more difficult to maintain? More difficult to
test? Have a larger impact on compile time? Not lend itself well to
re-use? Thanks. /david

Jul 23 '05 #1
10 2519
* da********@warpmail.net:
[muddling oop thoughts]


OT.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #2
I see, clc++ is like physics: it only answers "how", never "why".

Let me try again: what are the implications of using structural
inheritance versus composition in a large C++ project?

Jul 23 '05 #3
da********@warpmail.net wrote:
I see, clc++ is like physics: it only answers "how", never "why".

Let me try again: what are the implications of using structural
inheritance versus composition in a large C++ project?


I think you are looking for some "silver bullet". Check this article
regarding "silver bullets":

http://www.itworld.com/AppDev/710/lw...up/page_1.html


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #4
Ioannis Vranos wrote:
da********@warpmail.net wrote:
I see, clc++ is like physics: it only answers "how", never "why".

Let me try again: what are the implications of using structural
inheritance versus composition in a large C++ project?


I think you are looking for some "silver bullet". Check this article
regarding "silver bullets":

http://www.itworld.com/AppDev/710/lw...up/page_1.html


[Q. what would you lie to see added to the standard?]

Bjarne Stroustrup:
GUI: It would be nice to have a standard GUI framework, but I don't see how
that could be politically feasible.
Platform-independent system facilities: I'd like to see the Standard
Library provide a broader range of standard interfaces to common system
resources (where available), such as directories and sockets.

Hey no fair Stroustrup! What would be left for old Dead Dick Vic to moan
about?
Jul 23 '05 #5
This article does not seem to address my question in the slightest, but
thanks.

Jul 23 '05 #6
Structural inheritance is fine if your design respects the LSP (Liskov
Substitution Principle) -- basically, that all operations that operate
on base-class objects can have derived-class objects substituted and
operate correctly. Composition is safer in that it doesn't inherently
advertise LSP conformance, although you tend to type more. :)

I have found that the problem is that although it is fairly easy to
design hierarchies respecting the LSP at the start of a large project,
modifications made in midstream have a good chance of causing LSP
violations if your relationships really shouldn't have been "IS-A" to
begin with, leading to either kludges or extensive refactoring. YMMV.

More info on the LSP:
http://www.objectmentor.com/resources/articles/lsp.pdf

Matt

Jul 23 '05 #7

<da********@warpmail.net> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Structural inheritance (inheriting implementation) is equivalent to
composition in that a particular method must either call 'Base::foo' or
invoke 'base.foo'. Apparantly, The Literature tells us to prefer
composition over inheritance. Can anyone provide some reasons why this
is the case (based on "real-world" experience)? For example, is
structural inheritance more difficult to maintain? More difficult to
test? Have a larger impact on compile time? Not lend itself well to
re-use? Thanks. /david


If you inherit to add functionality, the child needs to #include the parent
in the header.
If you add functionality by aggregating, you can choose to just add a
pointer to the class.
The benefit of this would be, that you have isolated the knowledge to the
cpp files that
uses the header. It is worth a lot, when you are working on large projects.
Jul 23 '05 #8
mwigdahl wrote:
Structural inheritance is fine if your design respects the LSP (Liskov
Substitution Principle) -- basically, that all operations that operate
on base-class objects can have derived-class objects substituted and
operate correctly. Composition is safer in that it doesn't inherently
advertise LSP conformance, although you tend to type more. :)


Huh? OP is talking about inheritance that does not implement the IS-A
relationship. There's abosolutely no requirement for this type of
inheritance to satisfy LSP. LSP is simply not applicable to this type of
inheritance.

--
Best regards,
Andrey Tarasevich
Jul 23 '05 #9
da********@warpmail.net wrote:
Structural inheritance (inheriting implementation) is equivalent to
composition in that a particular method must either call 'Base::foo' or
invoke 'base.foo'. Apparantly, The Literature tells us to prefer
composition over inheritance. Can anyone provide some reasons why this
is the case (based on "real-world" experience)? For example, is
structural inheritance more difficult to maintain? More difficult to
test? Have a larger impact on compile time? Not lend itself well to
re-use?


There are absolutely no serious problems with this type of inheritance
as long as it is implemented through private inheritance. Although it is
worth pointing out that aggregation (as opposed to inheritance) is in
general case more flexible. It is possible to aggregate several
instances of the same class, if necessary. You can also give a
meaningful name to the aggregated object, which makes the program more
readable. Neither is possible is case of inheritance. Whether all this
really makes a noticeable difference depends on the concrete situation.

However, sometimes in C++ language one has to employ _public_ structural
(i.e. non-IS-A) inheritance in order to use certain convenient and
well-established implementational techniques. This is often frowned upon
because the popular belief is that public inheritance in C++ shall only
be used to implement IS-A relationships (LSP, etc.). I personally don't
agree with this view of public inheritance in C++ (or, more precisely, I
consider it to be unnecessarily extreme), but don't be surprised if you
meet someone who does.

--
Best regards,
Andrey Tarasevich
Jul 23 '05 #10
Yes, I reread (slower, this time) and you are right. Sorry!

Matt

Jul 23 '05 #11

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

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can...
3
by: LC | last post by:
hi, i worry about people doing something they shouldn't to my db and I would like to track any structural changes (who and which)to my db. I am...
4
by: JKop | last post by:
I'm starting to think that whenever you derive one class from another, that you should use virtual inheritance *all* the time, unless you have an...
2
by: adam.spamfree | last post by:
Hi, I was just wondering if anyone could give me an explanation of what the difference between "structural" and "presentational" elements is....
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...
7
by: Mike McGavin | last post by:
Hi everyone. I'm searching for a quick and dirty way to have psql record the SQL statements that I enter, especially those related to the...
1
by: Hans | last post by:
In developer studio 2003, I created a solution containing a C# windows app. I want to re-engeneer the app using Visio Professional 2003. How can...
2
by: Graville | last post by:
All, OK wasn't sure where to post this one but this should hopefully be ok. I am looking for a way to streamline some of the process within our...
1
by: Froefel | last post by:
Hi group, I've been developing a number of classes, many of which have a similar structure, as follows: namespace { public class classname...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.