C#应该有多重继承吗? [英] Should C# have multiple inheritance?

查看:33
本文介绍了C#应该有多重继承吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了许多反对在 C# 中包含多重继承的论点,其中一些包括(撇开哲学论点):

I have come across numerous arguments against the inclusion of multiple inheritance in C#, some of which include (philosophical arguments aside):

  • 多重继承太复杂,而且往往含糊不清
  • 这是不必要的,因为接口提供了类似的东西
  • 当接口不合适时,组合是一个很好的替代品

我有 C++ 背景,想念多重继承的力量和优雅.尽管它并不适合所有软件设计,但在某些情况下很难否认它在接口、组合和类似的面向对象技术上的实用性.

I come from a C++ background and miss the power and elegance of multiple inheritance. Although it is not suited to all software designs there are situations where it is difficult to deny it's utility over interfaces, composition and similar OO techniques.

排除多重继承是否意味着开发人员不够聪明,无法明智地使用它们,并且无法解决出现的复杂性?

Is the exclusion of multiple inheritance saying that developers are not smart enough to use them wisely and are incapable of addressing the complexities when they arise?

我个人欢迎将多重继承引入 C#(可能是 C##).

I personally would welcome the introduction of multiple inheritance into C# (perhaps C##).

附录:我很想知道谁来自单一(或程序背景)与多重继承背景的答复.我经常发现,没有多重继承经验的开发人员往往会因为没有任何范式经验而默认使用多重继承是不必要的论点.

Addendum: I would be interested to know from the responses who comes from a single (or procedural background) versus a multiple inheritance background. I have often found that developers who have no experience with multiple inheritance will often default to the multiple-inheritance-is-unnecessary argument simply because they do not have any experience with the paradigm.

推荐答案

我从来没有错过它,从来没有.是的,它 [MI] 变得复杂,是的,接口在很多方面都做着类似的工作——但这​​不是最重要的一点:一般来说,大多数时候根本不需要它.在许多情况下,甚至单继承也被过度使用.

I've never missed it once, not ever. Yes, it [MI] gets complicated, and yes, interfaces do a similar job in many ways - but that isn't the biggest point: in the general sense, it simply isn't needed most of the time. Even single inheritance is overused in many cases.

这篇关于C#应该有多重继承吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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