How to solve this diamond inheritance problem [closed]

0

Can anyone solve this problem (diamond inheritance) with the use of Interfaces and post here in C #? I found it in this post: why C # does not allow multiple inheritance? but I could not solve it.

Inheriting many concrete classes is a major source of problems from the point of view of designing a programming language: what if the two superclasses have a method of the same name? What if you have instance variables of the same name? A particularly complicated problem is the diamond inheritance . Consider the following inheritance pattern:

  A
 / \
B   C
 \ /
  D

A is a superclass that defines a virtual method foo (). B and C are classes that inherit from A and reimplement foo. Finally, D is a class that inherits multiple of B and C. Now, if we do

A obj = new D();

obj.foo();

What version of the method is called? Is the version defined in B or a defined in C?

Because of these complications, many programming languages (including C # and Java) prefer to make things simpler and allow only simple inheritance.

That said, it may be that the language provides alternatives to some of the more common uses of multiple inheritance. For example, C # allows a class to implement more than one Interface, which is similar to inheriting multiply from purely abstract classes.

    
asked by anonymous 02.07.2018 / 20:18

1 answer

3

Today, this is not possible in the language, however, in version 8 of C #, it will be possible to have the default implementation of methods on interfaces, anyway, one of the interfaces should be implemented explicitly.

    
02.07.2018 / 21:36