473,796 Members | 2,864 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 #1
15 7206
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******** ********@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 #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******** ********@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 #4
John Wood <sp**@isannoyin g.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.co m>
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**********@l vrREMOVE.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******** ********@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 #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.co m> wrote in message
news:%2******** *******@TK2MSFT NGP12.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******** ********@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 #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******** ********@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 #10

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

Similar topics

14
6410
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
4339
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
20
10087
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
23386
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
3653
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
60
4946
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
1691
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
9525
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10452
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
9050
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...
0
6785
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();...
0
5440
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...
0
5569
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
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
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
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.