为什么单继承? [英] Why single inheritance??

查看:89
本文介绍了为什么单继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



为什么C#不允许多重继承?这背后的原因是什么?

是否有任何优势,或者它只是一种方法来避免一些问题(如果是这样,有什么问题吗?)多重继承?


问候,

Sinex

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

推荐答案

用非常简单的话说 -


使设计更简单


有关详细信息,请参阅 http://tinyurl.com/36bzy


--------------- -----------------------------

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


" Sinex" <毫安************ @ honeywell.com>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP12.phx.gbl ...
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...

为什么C#不允许多重继承?这背后的原因是什么?
是否有任何优势,或者它只是一种方法来避免一些问题(如果
那么,有什么问题?)带有多重继承?

问候,
Sinex
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



引入接口作为多重继承的替代方案。

当你只能从一个基类继承,你可以根据需要实现

多个接口。
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.


很多人说如果你''使用多重继承,那么你就是

设计可能搞砸了。虽然这是值得商榷的,但通常如果你认为它稍微有点儿你可以找到一个更整洁(更好?)的方式来实现你在没有使用多个的情况下做的事情继承。


有趣的是,它不像CLR不能支持多个

继承。 Smalltalk在CLR下实现了这一点,但使用了一种形式的

聚合(委托)来实现它。而且我敢肯定,任何尝试使用其他语言的这些对象的任何尝试都会显示实现多么混乱

的多重继承(我想你会是通过成员

变量来获取父类)。我相信Eiffel也支持多种

的继承权。


-

John Wood

电子邮件:priorganize.com上的名字,点,名字

" Sinex" <毫安************ @ honeywell.com>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP12.phx.gbl ...
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...

为什么C#不允许多重继承?这背后的原因是什么?
是否有任何优势,或者它只是一种方法来避免一些问题(如果
那么,有什么问题?)带有多重继承?

问候,
Sinex
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



这篇关于为什么单继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆