C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

structural inheritance bad?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
davidrubin@warpmail.net
Guest





PostPosted: Fri Jan 28, 2005 5:09 am    Post subject: structural inheritance bad? Reply with quote



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

Back to top
Alf P. Steinbach
Guest





PostPosted: Fri Jan 28, 2005 5:21 am    Post subject: Re: structural inheritance bad? Reply with quote



* [email]davidrubin (AT) warpmail (DOT) net[/email]:
Quote:
[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?

Back to top
davidrubin@warpmail.net
Guest





PostPosted: Fri Jan 28, 2005 5:35 am    Post subject: Re: structural inheritance bad? Reply with quote



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?

Back to top
Ioannis Vranos
Guest





PostPosted: Fri Jan 28, 2005 5:40 am    Post subject: Re: structural inheritance bad? Reply with quote

[email]davidrubin (AT) warpmail (DOT) net[/email] wrote:

Quote:
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-02-stroustrup/page_1.html




--
Ioannis Vranos

http://www23.brinkster.com/noicys

Back to top
Adios
Guest





PostPosted: Fri Jan 28, 2005 10:59 am    Post subject: Re: structural inheritance bad? Reply with quote

Ioannis Vranos wrote:

Quote:
davidrubin (AT) warpmail (DOT) 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-02-stroustrup/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?

Back to top
davidrubin@warpmail.net
Guest





PostPosted: Fri Jan 28, 2005 1:13 pm    Post subject: Re: structural inheritance bad? Reply with quote

This article does not seem to address my question in the slightest, but
thanks.

Back to top
mwigdahl
Guest





PostPosted: Fri Jan 28, 2005 7:38 pm    Post subject: Re: structural inheritance bad? Reply with quote

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

Back to top
Jesper Madsen
Guest





PostPosted: Fri Jan 28, 2005 8:43 pm    Post subject: Re: structural inheritance bad? Reply with quote


<davidrubin (AT) warpmail (DOT) net> wrote

Quote:
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.



Back to top
Andrey Tarasevich
Guest





PostPosted: Fri Jan 28, 2005 9:49 pm    Post subject: Re: structural inheritance bad? Reply with quote

mwigdahl wrote:
Quote:
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. Smile

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

Back to top
Andrey Tarasevich
Guest





PostPosted: Fri Jan 28, 2005 10:02 pm    Post subject: Re: structural inheritance bad? Reply with quote

[email]davidrubin (AT) warpmail (DOT) net[/email] wrote:

Quote:
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

Back to top
mwigdahl
Guest





PostPosted: Fri Jan 28, 2005 10:51 pm    Post subject: Re: structural inheritance bad? Reply with quote

Yes, I reread (slower, this time) and you are right. Sorry!

Matt

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.