473,714 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2658
* da********@warp mail.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********@warp mail.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********@warp mail.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********@war pmail.net> wrote in message
news:11******** **************@ c13g2000cwb.goo glegroups.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********@warp mail.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 implementationa l 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

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

Similar topics

2
4377
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 not compile the file inheritance.cpp because the two files containing some templates: adjacency_list.hpp and mem_fn.hpp can not compile. Does anyone have any solutions?
3
4759
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 using oracle 8.0.6.0.0 and 9.2.0.2.0. regards, Lee Cho
4
2899
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 explicit reason not to. I'm even thinking that there shouldn't have been a "virtual" keyword for this purpose, but instead, a "nonvirtual" keyword! In teaching inheritance, you see the common example: class Vehicle {}
2
2148
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. thanks a lot.
22
23376
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 examples?
7
1802
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 database structure. My main motivation is to help keep what will probably be a production server up-to-date with my development server. I've thought a little about replication, but the current options for that seem like overkill for the relatively small database that I have. I'm particularly
1
2003
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 I make visio create the structural diagram??? Hans.
2
2137
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 dev team. One of the areas that often takes time and gets missed by the guys is the generation of SQL Scripts and checking them into sourcecontrol. I know that using SQL Server profiler you directly trace ALTER, DELETE and CREATE statements on all objects in your database. You can also
1
1169
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 { Private Fields
0
8815
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
9318
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...
1
9080
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
9033
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...
0
7960
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6638
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
5961
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();...
2
2529
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2113
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.