473,804 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why single inheritance??

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 inheritance?

regards,
Sinex
Nov 16 '05
15 7207
>> How is single inheritance with interfaces any different than multiple
inheritance where you only inherit 1 non-pure and many pure abstract bases ?
<<
Well er, it's basically the same. But that's not what people do when they're
talking about multiple inheritence, they're talking about multiple
implementation inheritence, not interface or abstract class.
Many people have suggested that this can be considerred good practice in multiple inheritance as well since it creates simpler sometimes more
flexible code (per bad design of default behaviors) and good programmers are
expensive. <<

Not sure how the 'and good programmers are expensive' bit links in to the
sentence but...
I agree that those times you want multiple inheritence should be a time to
step back and ask why you want it, and most of the time you end up realizing
that using interfaces and perhaps some aggregation (and encapsulation) is
actually a better solution.

Smalltalk offers multiple inheritence, but then again smalltalk lets you add
methods to existing objects, derive from primitive types and do all kinds of
weird things. It's basically a very liberal OOP language, which is nice n
all, but it comes with a huge performance penalty. And probably a huge
design penalty too.

--
John Wood
EMail: first name, dot, second name at priorganize.com
"Greg Young" <gr********@pla netbeach.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
ok everyone seems to have had their word ... Let me approach this
differently.

How is single inheritance with interfaces any different than multiple
inheritance where you only inherit 1 non-pure and many pure abstract bases ?
Many people have suggested that this can be considerred good practice in
multiple inheritance as well since it creates simpler sometimes more
flexible code (per bad design of default behaviors) and good programmers are expensive. The cost of the simpler code is the ability to provide default
behaviors in your many pure abstracts, if you are designing properly this
will probably not be a major issue.

Cheers,

Greg

"Sinex" <ma************ @honeywell.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
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 inheritance?

regards,
Sinex


Nov 16 '05 #11
On 22 Jun 2004 16:20, "Greg Young" wrote:
ok everyone seems to have had their word ... Let me approach this
differently.

How is single inheritance with interfaces any different than multiple
inheritance where you only inherit 1 non-pure and many pure abstract bases ?

Many people have suggested that this can be considerred good practice in
multiple inheritance as well since it creates simpler sometimes more
flexible code (per bad design of default behaviors) and good programmers are
expensive. The cost of the simpler code is the ability to provide default
behaviors in your many pure abstracts, if you are designing properly this
will probably not be a major issue.

Cheers,

Greg


It's probably no different, I would have thought, and is pretty much exactly
what C#/.NET gives you.
But it is different to inheriting multiple non-pure abstract bases which
is the main point, I guess.
--
Simon Smith
simon dot s at ghytred dot com
http://www.ghytred.com/NewsLook - Usenet for Outlook
Nov 16 '05 #12
"John Wood" <sp**@isannoyin g.com> wrote in message
news:uy******** ******@TK2MSFTN GP11.phx.gbl...
I believe Eiffel supports multiple
inheritence this way also.


Eiffel implements multiple inheritance by creating shadow interfaces. The
CLR thinks that it's just single inheritance. Inside an Eiffel system, it
looks like MI, so you get the benefits of a language that supports MI
properly.

--
Mickey Williams
Author, "Microsoft Visual C# .NET Core Reference", MS Press
www.servergeek.com/blogs/mickey
Nov 16 '05 #13
Sinex wrote:
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 inheritance?


Dreaded diamond pattern, for example:

http://www.parashift.com/c++-faq-lit....html#faq-25.8

Although a more comprehensive analysis of the tradeoffs for using multiple
inheritence and other techniques is in the previous FAQ:

http://www.parashift.com/c++-faq-lit....html#faq-25.6

Bottom line: Using MI correctly can be difficult, and the authors of C#
(and Java and more than a few other object languages, for that matter) felt
that it was safer to offer only single inheritance.

Of all the features missing from C#, multiple inheritance hasn't ever seemed
to be that big a deal to me...at least compared to things like
templates/generics (which eliminiates some of the needs for MI anyway.)

--
Reginald Blue
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my
telephone."
- Bjarne Stroustrup (originator of C++) [quoted at the 2003
International Conference on Intelligent User Interfaces]
Nov 16 '05 #14
John Wood wrote:
Smalltalk offers multiple inheritence,
It doesn't (maybe except S#, which is a Smalltalk derivative that goes
beyond the Smalltalk specification in order to be able to use the CLR)...
but then again smalltalk lets you add
methods to existing objects,
Even at runtime, pretty cool ;-)
derive from primitive types
Smalltalk doesn't have something like a "primitive type", they are
completely normal classes that inherit from "Object", so you can derive from
them as they are nothing special like, say, in Java.
and do all kinds of weird things.
What do you consider "weird things" ?
It's basically a very liberal OOP language, which is nice n
all, but it comes with a huge performance penalty.
It's not that huge anymore. The executing speed with modern VM's comes very
close to Java and C#
And probably a huge design penalty too.


Could you elaborate on this ?

Cheers
Michael
Nov 16 '05 #15
> > And probably a huge design penalty too.

Could you elaborate on this ?
Well 'huge' may be an exaggeration.

From experience I can say that liberal languages are easier to abuse. They
provide so many options, that usually in a moment of weakness the developer
chooses the easiest option, which isn't necessarily the best option.

A classic example is with C (and to a lesser extent C++), which let you do
pretty much anything with a pointer.

The comment stemmed from the thought that both MI, and the concept of adding
methods to existing objects, could easily be abused... and you could easily
end up with a terrible design built from 'easiest route' choices.

Just my opinion and a passing thought.

--
John Wood
EMail: first name, dot, second name at priorganize.com
"Michael Voss" <mi**********@l vrREMOVE.deCAPS > wrote in message
news:40d91efa$1 @news... John Wood wrote:
Smalltalk offers multiple inheritence,
It doesn't (maybe except S#, which is a Smalltalk derivative that goes
beyond the Smalltalk specification in order to be able to use the CLR)...
but then again smalltalk lets you add
methods to existing objects,


Even at runtime, pretty cool ;-)
derive from primitive types


Smalltalk doesn't have something like a "primitive type", they are
completely normal classes that inherit from "Object", so you can derive

from them as they are nothing special like, say, in Java.
and do all kinds of weird things.
What do you consider "weird things" ?
It's basically a very liberal OOP language, which is nice n
all, but it comes with a huge performance penalty.


It's not that huge anymore. The executing speed with modern VM's comes

very close to Java and C#
And probably a huge design penalty too.


Could you elaborate on this ?

Cheers
Michael

Nov 16 '05 #16

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

Similar topics

14
6413
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 is the right and common case to call init: class Mother(object): def __init__(self, param_mother): print 'Mother'
2
4340
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
20
10090
by: km | last post by:
Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in advance for enlightment ... here's the snippet #!/usr/bin/python
22
23389
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?
0
1931
by: Laharl | last post by:
This is what I am trying to do: public abstract class A : ISerializable { public A(SerializationInfo info, StreamingContext context){} public void GetObjectData(SerializationInfo info, StreamingContext context) {} } public abstract class B : A, ISerializable
5
4762
by: AJ | last post by:
Is multiple inheritance is possible in C#?
47
3657
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
60
4950
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the 'target' programming community herein) to get some community input and verify (or not) the following two statements. Few programmers (3 to7%) UNDERSTAND 'Strategic Functional Migration
18
1694
by: GD | last post by:
Please remove ability to multiple inheritance in Python 3000. Multiple inheritance is bad for design, rarely used and contains many problems for usual users. Every program can be designed only with single inheritance. I also published this request at http://bugs.python.org/issue2667
0
9712
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
10595
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...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10341
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,...
1
7634
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
5530
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4308
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 we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
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.