LogFAQs > #926131673

LurkerFAQs, Active DB, DB1, DB2, DB3, DB4, Database 5 ( 01.01.2019-12.31.2019 ), DB6, DB7, DB8, DB9, DB10, DB11, DB12, Clear
Topic List
Page List: 1
TopicJust training my neural net, AMA
Sahuagin
08/16/19 1:46:17 AM
#14:


Yellow posted...
The reason they give is that the compiler wouldn't be able to figure out which overrides to use, which is silly, because you can just give the classes you want to inherit from highest priority to lowest in a list, like every other modern language.
the main reason I think they give (might be what you mean here) is "the diamond problem", which is if B and C inherit from A, and then D inherits from B and C, what if B and C have conflicting/colliding members? and even if you have a workaround rule, you've still violated LSP for either B or C. (a D should be able to be treated both as if it was a B, and as if it was a C).

really, though, they could just give an error when a conflicting member exists or something else like that. I kind of agree that that's a weak reason, since other languages have already done it.

I think another better reason they don't implement it is because "multiple inheritance is bad". C# is a language designed in a lot of ways to be the anti-C++ and to avoid as many of the problems with C++ as possible, and one of those problems is multiple-inheritance.

https://stackoverflow.com/questions/406081/why-should-i-avoid-multiple-inheritance-in-c

a problem with inheritance, and using base classes rather than interfaces, is that it makes your code dependent on a particular implementation (or, particular set of implementations). inheritance is best used sparingly, and in situations where you want to treat a bunch of related objects as the same kind-of-thing, pushing common members into the base. (the idea of having a bunch of classes ready to be inherited from and inheriting from combinations of them does not work out as great as it sounds and leads to big messes. (inheritance is a tight coupling, whereas what we really want is loosely coupled code.))

for example, maybe your function uses only a single property of the object it asks for. asking for a ThingBase instead of a ConcreteThing is slightly better, but way better still is asking for an IHaveThatOnePropertyYouWant reference instead.

(basically, while MI can be useful, most of the time it's really just a way to make your code worse.)

Soon C# will have default interface implementations (though I think they're slightly controversial), which is very similar to multiple inheritance. and eventually there will be mixins, which are also similar but not exactly the same. (IIRC mixins allow you to auto-implement an interface by accepting a reference to something else that has already implemented it; calls made to your object for that interface just get forwarded to the other object.)

---
... Copied to Clipboard!
Topic List
Page List: 1