What do you call it when one interface “inherits” from another?

☆樱花仙子☆ 提交于 2020-01-09 04:39:05

问题


If I have class B : A {}

I say that "Class B inherited class A" or "class B derives from class A".

However, if I instead have:

  class B : ISomeInterface   {}

it's wrong to say "B inherits ISomeInterface" -- the proper term is to say "B implements ISomeInterface".

But, say I have

  interface ISomeInterface : ISomeOtherInterface   {}

Now, it's still wrong to say "inherits", but it's now just as wrong to say "implements" since ISomeInterface doesn't implement anything.

So, what do you call that relationship?


回答1:


I personally say "extends" and I thought the C# spec uses that word as well somewhere (I can't find it now, unfortunately) - but I remember Eric Lippert saying he wasn't keen on it, and wanted to change it for 4.0.

I think it's good, because it shows that you're extending the contract specified by the original interface.

EDIT: Having looked at the 3.0 spec...

The spec sort of side-steps the issue in section 13.2. It talks about the members being inherited from the base interfaces. It talks about one class extending another, but not interfaces

EDIT: In the C# 5 spec, section 13.1.4, it uses inherits:

An interface can inherit from zero or more interface types

So that's probably the best term to use.




回答2:


I call it "extends".




回答3:


Usually, I call it overengineering.




回答4:


As an authoritative source and in case you need a helpful quote, I came across info on MSDN that describes "interface inheritance" with a practical example of the interface inheritance structure for the ComboBox, Control, Listbox and TextBox:

And with mention of an explicit base interface

An interface can inherit from zero or more interfaces, which are called the explicit base interfaces of the interface.

Example:

interface IControl
{
   void Paint();
}
interface ITextBox: IControl
{
   void SetText(string text);
}
interface IListBox: IControl
{
   void SetItems(string[] items);
}
interface IComboBox: ITextBox, IListBox {}

Source:

http://msdn.microsoft.com/en-us/library/aa664578%28VS.71%29.aspx




回答5:


Why would it be wrong to say InterfaceB "inherits" or "derives from" InterfaceA? "Implements" would be wrong, because InterfaceB doesn't provide an implementation. Semantically, deriving interfaces is very similar to deriving classes. C++, for example, doesn't distinguish between interfaces and classes at all.




回答6:


you've got the definition wrong.

B : A means "B inherits from A".

when we say "B implements InterfaceA", that usually means InterfaceA does not have the definition to function - it's only prototypes (or, PURE in C++). However in C++ and most OOPL, the inherit and implement shares same syntax.

So, InterfaceB : InterfaceA still means "InterfaceB inherits InterfaceA".



来源:https://stackoverflow.com/questions/807217/what-do-you-call-it-when-one-interface-inherits-from-another

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!