0

If C# allowed inheritance from multiple classes, provided that at most one of them had data fields, interfaces would be redundant.

Such field-less abstract classes would be superior to interfaces in many ways. For example we could have default implementations (coming as a new language feature only in C# 8.0), or utility methods related to the interface. The language would be simpler with one concept less.

kaalus
  • 4,475
  • 3
  • 29
  • 39

1 Answers1

3

No, the language would not be simpler - on the contrary:

  • Readers of your code would have no idea if your abstract class has fields or not, so they would have to read your code to see if you are sharing an interface or an implementation
  • Interfaces could be implemented by value types. You would have to make an exception for "fieldless" abstract classes, or create an abstract struct to replace interface
  • An extension method could be employed in place of a default implementation to share code "horizontally"
  • Since adding fields to an abstract class would make it ineligible for multiple inheritance, expanding the base class would break derived classes.

That is a pretty high price to pay for dropping a keyword from the language.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523