In the C# specification for Interface (https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/interfaces#interface-implementations), there is an example regarding a class implements multiple interfaces:
interface IControl
{
void Paint();
}
interface ITextBox: IControl
{
void SetText(string text);
}
interface IListBox: IControl
{
void SetItems(string[] items);
}
class ComboBox: IControl, ITextBox, IListBox
{
void IControl.Paint() {...}
void ITextBox.SetText(string text) {...}
void IListBox.SetItems(string[] items) {...}
}
My question is not about Implicit and Explicit implementation, I was wondering why people wants to include the base interface(IControl
in this example) in the class definition? Isn't following definition good enough?
class ComboBox: /*IControl,*/ ITextBox, IListBox
{
void Paint() {...}
void ITextBox.SetText(string text) {...}
void IListBox.SetItems(string[] items) {...}
}
Another example is in the List
definition, its base interface list includes the base interfaces of IList<T>
and ILit
, why?
interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable
interface IList : ICollection, IEnumerableclass
List<T> : IList<T>, ICollection<T>, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable