为什么vb.net不支持多重继承? [英] why does vb.net not support multiple inheritance?

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

问题描述

我已经看到了,为什么C#不实现多重继承,但很少,为什么它不支持在VB中一些讨论。据我所知,C#和VB编译到中介语,所以他们都需要共享类似的限制。

I've seen some discussion on why c# does not implement multiple inheritance but very little as to why it isn't supported in vb. I understand that both c# and vb are compiled down to intermediary language and so they both need to share similar restrictions.

多重继承的VB缺乏似乎已经给出的原因之一缺少点网的功能。没有人知道为什么VB不支持多重继承?我希望的一点历史的教训,并讨论为什么这个从未被认为是VB的。

The lack of multiple inheritance in VB seems to have been given as one reason for the lack of the feature in dot net. Does anyone know why VB doesn't support multiple inheritance? I'm hoping for a bit of history lesson and discussion on why this was never considered for VB.

推荐答案

这不是在CLR实现的,因此不符合CLS的语言,比如VB.NET可用。似乎有工程师在微软,包括安德斯·海尔斯伯格,C#首席设计师中一个普遍的共识,即潜在的好处是不值得实施的成本和复杂性。克里斯Brumme,在.NET队当时一位杰出的工程师表示,这早在2004年:

It isn't implemented in the CLR so it isn't available in CLS-compliant languages like VB.NET. There seems to be a general consensus among engineers at Microsoft, including Anders Hejlsberg, C# lead architect, that the potential benefits are not worth the cost and complexity of implementation. Chris Brumme, a distinguished engineer on the .NET team at the time, said this back in 2004:

有我们没有提供一个烤的,可核查的,符合CLS的多重实现继承的版本有几个原因:

There are several reasons we haven't provided a baked-in, verifiable, CLS-compliant version of multiple implementation inheritance:

      
  1. 不同的语言实际上是对MI的工作原理不同的期望。例如,如何解决冲突和重复基地是否合并或冗余。之前,我们可以在CLR实现MI,我们要做的所有语言的调查,找出共同的概念,并决定如何PSS他们前$ P $的语言无关的方式。我们还必须决定MI是否属于在CLS和什么这意味着对于那些不想这个概念(presumably VB.NET,例如)语言。当然,这是我们作为一个公共语言运行库的企业,但我们还没有得到周围做心梗呢。

  1. Different languages actually have different expectations for how MI works. For example, how conflicts are resolved and whether duplicate bases are merged or redundant. Before we can implement MI in the CLR, we have to do a survey of all the languages, figure out the common concepts, and decide how to express them in a language-neutral manner. We would also have to decide whether MI belongs in the CLS and what this would mean for languages that don't want this concept (presumably VB.NET, for example). Of course, that's the business we are in as a common language runtime, but we haven't got around to doing it for MI yet.

的地方MI是真正合适的数量其实是相当小的。在许多情况下,多接口继承可以完成这项工作,而不是。在其他情况下,您可以使用封装和代表团。如果我们添加一个稍微不同的结构,如混入,会实际上是更厉害?

The number of places where MI is truly appropriate is actually quite small. In many cases, multiple interface inheritance can get the job done instead. In other cases, you may be able to use encapsulation and delegation. If we were to add a slightly different construct, like mixins, would that actually be more powerful?

多重实现继承注入大量的复杂性进入实施。这种复杂性影响铸造,布局,调度,字段访问,序列化,身份比较,可验证性,反思,仿制药,而且很可能其他很多地方。

Multiple implementation inheritance injects a lot of complexity into the implementation. This complexity impacts casting, layout, dispatch, field access, serialization, identity comparisons, verifiability, reflection, generics, and probably lots of other places.

这不是完全清楚,这个功能会为自己支付。这是我们经常问。这件事情我们还没有上进行尽职调查。但我的直觉告诉我,我们已经做了深刻检查之后,我们仍然决定离开该功能未实现。

It's not at all clear that this feature would pay for itself. It's something we are often asked about. It's something we haven't done due diligence on. But my gut tells me that, after we've done a deep examination, we'll still decide to leave the feature unimplemented.

[链接]

底线是,我不认为我的呼吸。

Bottom line is I would not hold my breath.

现在,你可以通过继承多个接口和委托执行到包含的类实例获得一定的多重实现继承的好处,如果不是大多数。这是多一点的工作,但它是我们现在所拥有的最好的。

For now, you can gain some if not most of the benefits of multiple implementation inheritance by inheriting multiple interfaces and delegating the implementation to a contained class instance. It's a little more work but it is the best we have right now.

我还应该注意到,我写了C ++的全职好几年了,只杠杆式多重继承我自己设计了两三次。这是方便,当我需要它,但老实说,我不觉得自己希望它在C#中非常频繁。

I should also note that I wrote C++ full-time for several years and only leveraged multiple inheritance a couple of times in my own designs. It was handy when I needed it, but honestly I don't find myself wishing for it in C# very often.

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

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