What are the benefits of inheriting from multiple classes?

I saw some comments on the forums, and it seems that people want to inherit from several classes in C #. Why do you need this? I cannot think of any good for this, but since there are people who want this, there must be some.

+5
source share
4 answers

Well, here is an example of ASP.NET WebForms:

I have one base class, a web control, let's say it's simple TextBox.

I then inherit from TextBoxto provide formatting RichTextBox.

Then I want to have TextBoxone that can spell check SpellCheckingTextBox.

, SpellCheckingRichTextBox? .

: ISpellCheckingTextBox IRichTextBox SpellCheckingRichTextBox. TextBox, .

, . , ID?

+3

, , , ++. #. , IMO, , . , , . N

, , , , , MI.

+1

One legitimate case for wanting it in C # is to create a derived MarshalByRef object. For example, let's say I want to do the following:

public class FooCorpClass
{
  // This class is defined in a 3rd party library and thus can't be changed
}

public class MyFoo : FooCorpClass, MarshalByRef
{
  // I can't do this because MarshalByRef isnt' an interface
}

Personally, I see that it is a shame that you cannot have multiple inheritance if there are no collisions, or there are collision processing mechanisms, but they are interruptions.

0
source

All Articles