Home c# Why in C # refused multiple class inheritance?

Why in C # refused multiple class inheritance?




Friends, explain or throw off the link where you can find the answer to the question “Why in C # refused multiple class inheritance?”

Answer 1, Authority 100%

TL; DR: to add multiple inheritance adds a lot of complexity, and few benefits from the use


translation Chris response Brumme the question Why does not C # support multiple inheritance?

There are several reasons why we did not implement multiple inheritance implementation directly. (As you know, we support multiple interface inheritance).

However, I must draw attention to the fact that compilers can create multiple inheritance to their types in the CLR. There are several problems to go this way: unverifiable result, the lack of interaction with other languages ​​through the CLS . Technique for creating some VTables in shnyh RVA-static fields. To address controlled methods (which may not even have been processed JIT), you are using design VTFixup. This structure is a table of triplets. Triples consist of a marker on the managed method, addresses in your image, which will need to be fixed (in this case, the slot in VTable you create shnyh RVA-static fields), and some flags. Possible flags are described in the corhdr.h . They allow you to specify the size of pointers: 32 bit vs 64 bit control virtual behavior, as well as whether there is any PInvoke reverse mode, which should be applied in the form of lazy evaluation, which ultimately transmitted to the control method. If we perform the transition unmanaged- & gt; managed , we can also control how AppDomain will be selected to send the call


There are several reasons why we have not provided an elaborate, verifiable, CLS-compatible version of the implementation of multiple inheritance:

  1. Different languages ​​have different expectations of how the multiple inheritance. For example, how to resolve conflicts, whether combined or duplicates discarded. Before we can implement multiple inheritance in the CLR, we have to make a review of all the languages, to define common concepts and decide how to express them in a neutral way. We have to decide whether to enter multiple inheritance in the CLS and what this will mean for languages ​​that do not want to support this concept (such as VB.NET). Of course it is our business to the CLR, but we have not yet found the time to do this for multiple inheritance.

  2. Places where multiple inheritance is good, actually very little. In many cases, running multiple inheritance of interfaces. In other cases, you can use the encapsulation and delegation. If we added another structure, such as mixins, it would be more powerful?

  3. Multiple implementation inheritance adds complexity to implement. This complexity affects the casting, serialize access to the fields of reflection and perhaps many other places.

It is still not clear that this option will pay for itself. This is what we often ask ourselves. This is something that we have not yet fully tested. But my gut tells that after in-depth analysis we decide not to add this feature.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions