Multiple inheritance is not supported on dotnet. But does it support multiple interfaces?

Possible duplicate:
Multiple Inheritance in C #

Multiple inheritance is not supported on dotnet. But several interfaces are supported. Why does this behavior exist. Any specific reasons?

+4
source share
6 answers

You can simulate multiple inheritance using interfaces. If multiple inheritance with classes is allowed, this will lead to a Diamond problem.
For reasons, multiple inheritance is not supported, I suggest you read Why does C # not support multiple inheritance?

Different languages โ€‹โ€‹really have different expectations about how MI works. For example, how conflicts are resolved and whether duplicate databases are duplicated combined or redundant. Before we can implement MI in the CLR, we need to review all the languages, the drawing, develop common concepts and decide how to express them in a language-neutral manner. We also need to decide if MI belongs to CLS, and what it would mean for languages โ€‹โ€‹that do not want this concept (presumably, for example, VB.NET). of Of course, the business in which we are as a common language of execution, but we have not reached this point for MI yet.

The number of places where the MI is really appropriate is actually quite small. In many cases, multiple interfaces can be inherited instead. In other cases, you may be able to use encapsulation and delegation. If we added a slightly different design, such as mixins, would it really be more powerful?

Multiple implementation inheritance introduces many difficulties to the implementation. This complexity hits, layout, sending, accessing fields, serializing, identifying comparisons, verifiability, reflection, generics, and possibly many other places.

+4
source

yes Inheritance means getting the properties of one class object to another class object.

here in the concept of the interface we donโ€™t have any properties at all, and we implement unrealized methods of the interface in the class ...

therefore inheritance and intefaces are completely opposite ...

so finally java only supports multiple inheritance syntax, doesn't support multiple inheritance implementation ....

Inheritance is like a debit, and the interface is like a credit .... but the interface has its meaning in other concepts, such as server-side programming ...

+2
source

In general, multiple inheritance creates more problems than it solves. Consider resolving virtual method calls. What if the class does not define the method, but both its parents? Which one should be performed?

Implementing multiple interfaces, however, does not have such problems. If two interfaces define the same method, and you are actually trying to implement them, your code will not even compile (although I'm not sure that you can explicitly implement them and satisfy the requirements of the compiler).

+1
source

Since interfaces are not implementation details, they only know what operations an object can perform. Multiple inheritance is difficult if there are two different methods for the same base class. But in the case of an interface, both interfaces can define a common method with the same signature, but they are not implemented on the level interface; they are executed only by an object or type that implement both interfaces. Here, although there are two different interfaces defining two methods with the same signatures, the object provides a common implementation that satisfies both methods in both interfaces. So there is no ambiguity between implementations , both methods have therefore you can have multiple inheritance in case of interfaces.

+1
source

The danger with multiple inheritance of specific classes is that there is a search for a repository and a virtual method that needs to be consistent between two or more parents of that class. It is especially difficult when there are common ancestors. But interfaces only determine what the class should look like, and not how it should be implemented, and it is much easier to make the class look like different things than to make it very diverse. Two interfaces may require the int Foo () method, and the implementing class can safely use both interfaces and implement Foo () without causing headaches for which the Foo () base is redefined, etc.

Another reason is because the chain of constructors is difficult to handle multiple inheritance. But the interfaces are not indicated by the constructors, so the problem is completely circumvented.

There are many other reasons why multiple inheritance is bad.

0
source
  java does not supports implementation of multiple inheritance ...

 some people says java supports multiple inheritance through interfaces ... but its not correct here the explanation:

 inheritance ::

 getting the properties from one class object to another class object ..

 Class A {}

 Class B extends A {}

 here object of class A getting the properties (methods / functions / & data members / class variables)

 why java does not supports multiple inheritance using classes:

 Class A {} Class B {} Class C extends A, B {} X - this statement causes error because Class A getting object of object class from both sides A and B ...

 every java class by default extending Object of object class ... and Object of object class is the root object means super class for all classes ...

 but here Class c having two super classes of object ... so giving error ... means java does not support multiple inheritance by using classes ..

 is java supports multiple inheritance using Interfaces ::

 because of this interface concept only few of us saying that java supports multiple inheritance .... but its wrong ..

 here the explanation ::

 interface A {}

 interface B {}

 interface C implements A, B {}

 (or) interface A {}

 interface B {}

 Class C implements A, B {}

 here its look like multiple inheritance but .....

 inheritance means getting the properties from one class object to another class object ..

 here in interface concept we are not at all getting any properties rather we are implementing the unimplemented methods of interface in class ...

 so inheritance and interactions are quite opposite ...

 so finally java supports only syntax of multiple inheritance does not supports implementation of multiple inheritance ....

 inheritance is like debit and interface is like credit .... but interface has its own importance in other concepts like server side programming ...
0
source

All Articles