473,385 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 #1
15 7162
In very simple words-

To make design simpler

For details discussion have a look on http://tinyurl.com/36bzy

--------------------------------------------
Manish Agarwal <ma***********@hotmail.com>
http://personal.vsnl.com/mkag

"Sinex" <ma************@honeywell.com> wrote in message
news:%2****************@TK2MSFTNGP12.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 #2
Interfaces were introduced as an alternative to multiple inheritance.
While you can only inherit from a single base class, you can implement
as many interfaces as you want.
Nov 16 '05 #3
A lot of people say that if you're using multiple inheritence, then you're
design is probably messed up. While it is debatable, usually if you think
about it a bit you can find a neater (better?) way of achieving what you're
doing without using multiple inheritence.

Interestingly though, it's not like the CLR cannot support multiple
inheritence. Smalltalk achieves this under the CLR, but using a form of
aggregation (delegation) to achieve it. And I'm sure any attempt to use
these objects in other languages will show just how messy the implementation
of multiple inheritence is (I imagine you'll be going through member
variables to get to the parent classes). I believe Eiffel supports multiple
inheritence this way also.

--
John Wood
EMail: first name, dot, second name at priorganize.com
"Sinex" <ma************@honeywell.com> wrote in message
news:%2****************@TK2MSFTNGP12.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 #4
John Wood <sp**@isannoying.com> wrote:
Interestingly though, it's not like the CLR cannot support multiple
inheritence. Smalltalk achieves this under the CLR, but using a form of
aggregation (delegation) to achieve it.
That's not the CLR supporting it though - that's Smalltalk effectively
emulating it. It's like claiming that the x86 supports the Z80
instruction set, just because there are Spectrum emulators available :)

The CLR cannot itself support multiple inheritence, IMO.
And I'm sure any attempt to use
these objects in other languages will show just how messy the implementation
of multiple inheritence is (I imagine you'll be going through member
variables to get to the parent classes).
Exactly.
I believe Eiffel supports multiple
inheritence this way also.


Yup, I believe so.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
John Wood wrote:
Interestingly though, it's not like the CLR cannot support multiple
inheritence. Smalltalk achieves this under the CLR, but using a form of
aggregation (delegation) to achieve it.


Can you tell which Smalltalk dialect uses the CLR and offers multiple
inheritance ?
Nov 16 '05 #6
Check out http://www.smallscript.org/ for more info.

--
John Wood
EMail: first name, dot, second name at priorganize.com
"Michael Voss" <mi**********@lvrREMOVE.deCAPS> wrote in message
news:40d84611$1@news...
John Wood wrote:
Interestingly though, it's not like the CLR cannot support multiple
inheritence. Smalltalk achieves this under the CLR, but using a form of
aggregation (delegation) to achieve it.


Can you tell which Smalltalk dialect uses the CLR and offers multiple
inheritance ?

Nov 16 '05 #7
Just my opinion - Multiple inheritance in C++ was nothing but a pain in the
booty. I am glad C# didn't allow it. Although, I believe they were trying to
make a language not as difficult / lower entry level than C++. Another such
language is Java. It has 99.9999% of what you need, and only leaves the
complex parts out. IMHO that's sensible - it leads to better code and
cheaper programmers.

Specifically what problems could Multiple Inheritance cause in .NET. .NET
has somethign called as 'fixed object reference' that is - object references
to the one object in refer to same pointer value regardless of the type that
the reference is being interpreted as. For multiple inheritance, you would
loose that and along with you would loose all base type
interpretations/castings to base types. Secondly, you would loose all highly
efficient pointer comparisons. Yes you have the unsafe block, but who uses
it anyway when it says in red lettering "unsafe" (I had totally forgotten
about "unsafe", until I was reminded of it in these groups). But, shallow
cloning, equality reference etc. none would be as straightforward if you
didn't have fixed object references. Also, for all practical purposes that
MI can be used for, interfaces can do the same, albeit with too many vtable
jumps (3 compared to 1) so it is not as efficient .. but for cleaner code
and better readability, I can live with that.

- Sahil Malik
Independent Consultant
You can reach me thru my blog - http://dotnetjunkies.com/WebLog/sahilmalik/

"Sinex" <ma************@honeywell.com> wrote in message
news:%2****************@TK2MSFTNGP12.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 #8
>> 'fixed object reference' that is - object references to the one object in
refer to same pointer value regardless of the type that the reference is
being interpreted as <<

wha? :)

--
John Wood
EMail: first name, dot, second name at priorganize.com
"Sahil Malik" <no****@ms.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Just my opinion - Multiple inheritance in C++ was nothing but a pain in the booty. I am glad C# didn't allow it. Although, I believe they were trying to make a language not as difficult / lower entry level than C++. Another such language is Java. It has 99.9999% of what you need, and only leaves the
complex parts out. IMHO that's sensible - it leads to better code and
cheaper programmers.

Specifically what problems could Multiple Inheritance cause in .NET. .NET
has somethign called as 'fixed object reference' that is - object references to the one object in refer to same pointer value regardless of the type that the reference is being interpreted as. For multiple inheritance, you would
loose that and along with you would loose all base type
interpretations/castings to base types. Secondly, you would loose all highly efficient pointer comparisons. Yes you have the unsafe block, but who uses
it anyway when it says in red lettering "unsafe" (I had totally forgotten
about "unsafe", until I was reminded of it in these groups). But, shallow
cloning, equality reference etc. none would be as straightforward if you
didn't have fixed object references. Also, for all practical purposes that
MI can be used for, interfaces can do the same, albeit with too many vtable jumps (3 compared to 1) so it is not as efficient .. but for cleaner code
and better readability, I can live with that.

- Sahil Malik
Independent Consultant
You can reach me thru my blog - http://dotnetjunkies.com/WebLog/sahilmalik/
"Sinex" <ma************@honeywell.com> wrote in message
news:%2****************@TK2MSFTNGP12.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 #9
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****************@TK2MSFTNGP12.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 #10
>> 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********@planetbeach.com> wrote in message
news:%2****************@TK2MSFTNGP09.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****************@TK2MSFTNGP12.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**@isannoying.com> wrote in message
news:uy**************@TK2MSFTNGP11.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**********@lvrREMOVE.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
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...
2
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
20
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...
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 understand why. Can anyone give me some concrete...
0
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,...
5
by: AJ | last post by:
Is multiple inheritance is possible in C#?
47
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
60
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...
18
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.