Why multiple inheritance is not supported in net




















What if a class doesn't define a method but both of its parents do? Which one should execute? Implementing multiple interfaces, however, has no such problems. If two interfaces define the same method and you actually try to implement them, your code won't even compile although I'm unsure if you could explicitly implement them and satisfy the compiler requirements.

Because interfaces do not the implementation details, they only know what operations an object can do. Multiple inheritance is difficult when there are two different implementations are found for the method with same signature in both the base classes. But in case of interface both the interface may define a common method with same signature but they are not implemented at the interface level, they are only implemented by the object or type that implement both the interfaces.

Here though there are two different interfaces defining two methods with same signatures, the object provides the common implementation satisfying both the methods in both the interfaces.

So there is no ambiguity between implementations , both the methods have common implementation hence you could have multiple inheritance in case of interfaces. The danger with multiple inheritance of concrete classes is that there is storage and virtual method lookup that must be reconciled between the two or more parents of a given class.

Especially tricky is when there are shared ancestors. But interfaces only define what a class should look like, not how it needs to be implemented and it's much easier to make a class look like a lot of different things than it is to make it be a lot of different things. Two interfaces can require a method int Foo and an implementing class can safely use both interfaces and implement Foo without causing headaches for which base Foo to override, etc.

Another reason is that constructor chaining is difficult to manage with multiple inheritance. But interfaces don't specify constructors, so that problem is entirely sidestepped. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. But multiple interface supports? Asked 11 years, 3 months ago. Active 8 years, 4 months ago.

Posted 7-Oct am Mukesh Pr sad. Multiple inheritance create tight coupling which make maintenance hard. For extensibility and reuse purpose, it is better to that your main object contains sub-object. At that point you can easily change a sub-object for a derived one and support a lot of combination. When it make sense, you might even be able to change a sub-object at run time or decide which sub-object to uses at creation time.

This give a lot of flexibility. One problem with multiple inheritance is that once you use it a lot, you will find that you often have the wrong combination of parent classes and you have a lot of refactoring to adjust the class hierarchy or create similar classes that differs only from one or 2 bases classes among a few one.

Say that you inherited from 3 classes and each of those have 3 subclasses. If you need all possibilities, you will have 4 x 4 x 4 possibilities for parents giving 64 combinations. On the other hand, if those are sub-object, then you have a single class with 4 possible classes for each sub-object. Also the parent class would have a lot of unctions and you might have to maintain around 70 to 80 classes if you change one virtual functions.

In the other case, you'll have to change only 4 classes Posted 7-Oct pm Philippe Mori. Add your solution here.

OK Paste as. Treat my content as plain text, not as HTML. Existing Members Sign in to your account. This email is in use. Do you need your password? Submit your solution! When answering a question please: Read the question carefully. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem.

Insults are not welcome. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid. Click here to know more about C Interfaces. Home C VB. Multiple inheritance in C Multiple inheritance allows programmers to create classes that combine aspects of multiple classes and their corresponding hierarchies. For ex. Net Interface An Interface looks like a class, it contain only the declaration of the members but has no implementation.

Difference between a Value Type and a Reference Type System level Exceptions Vs Application level Exceptions Difference between sub-procedure and function What does the term immutable mean What does the keyword static mean this.



0コメント

  • 1000 / 1000