描述接口之间的关系
考虑 FCL 中的这个接口:
public interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable
它告诉我们:接口 IList
[XXX] 3 个接口:IConnection
、IEnumerable
IEnumerable
。我对[XXX]有一些选择:
(1) 派生/继承
这个选项来自C#语言规范(但不是直接),其中有时会出现“多重继承接口”一词。我不喜欢它的原因:使用“继承”这个词,我们有:IEnumerable
继承IEnumerable
,ICollection
继承 IEnumerable
和 IEnumerable
,然后 IList
继承所有三个。有什么地方不对劲,但我又说不出来,感觉很不好。
(2)implements
这也不是一个好的选择。因为没有实施,它只是一个合同。
(3)还有什么?我想知道
你的想法是什么?
Consider this interface in FCL:
public interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable
It tells us: the interface IList<T>
[XXX] the 3 interfaces: IConnection<T>
,IEnumerable<T>
and IEnumerable
. I have some choices for [XXX]:
(1) derives from/inherits
This option comes from C# language specification(but not directly), where the word "multiple-inheritance interfaces" appears some times. The reason I don't like it: Using the word "inherit", we have: IEnumerable<T>
inherits IEnumerable
, ICollection<T>
inherits both IEnumerable<T>
and IEnumerable
, then IList<T>
inherits all the three. Something is wrong but I can't tell, very bad feelings.
(2) implements
It's not a good option either. Because there is no implementation, it's a contract only.
(3) something else? I'd like to know
What's your idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我为此使用了“扩展”。可能有点像 Java,但对我来说似乎很合适。具有超级接口的接口可以合理地说是“扩展”该接口,因为它必须向其添加一些东西(不一定或当然,但没有太多理由不这样做。除了语义原因,但然后你'仍然在语义上扩展)。
I used "Extends" for this. Might be a little Java-ish but it seems appropriate to me. An interface that has a super-interface can be reasonably said to "extend" that interface because it must add something to it (not necessarily or course, but there aren't many reasons not to. Except maybe semantic reasons, but then you're still extending semantically).
我会说
IList
包括ICollection
、IEnumerable< /code> 和
IEnumerable
或者,我可能会说它扩展
I'd say
IList<T>
includesICollection<T>
,IEnumerable<T>
, andIEnumerable
Alternatively, I might say it extends
我会说实现了一个接口并且继承了一个类。这就是你问的吗?
如果是,原因如下:
我不使用“继承”来描述这两种情况的原因是因为您没有从接口继承任何内容,例如接口没有功能实质 - 只是具体对象将做什么的蓝图。
I'd say an interface is implemented and a class is inherited. Is that what you're asking?
If yes, here's why:
The reason I don't use "inherits" do describe both situations is because you don't inherit anything from an interface, e.g. there is no functional substance to an interface - just a blueprint of what the concrete object will do.