【发布时间】:2010-02-27 04:13:31
【问题描述】:
我不一定看到接口继承接口的巨大好处。
考虑下面三个接口,第三个继承另外两个
interface IOne {
}
interface ITwo {
}
// interface inheritance
interface IAll : IOne, ITwo {
}
是不是最好
class C : IOne, ITwo { ... }
或
class C : IAll { ... }
如果后者可能是有益的,那么为什么不创建 IAll 以拥有 IOne 和 ITwo 的所有方法而不从它们继承呢?毕竟它是一个接口。
接口继承是否实用,而不仅仅是有用?
【问题讨论】:
-
如果你有大量的继承接口,你可以使用这个技巧来缩短行长。否则,在我看来,这是不必要的混淆(除非两个接口可以自然地组合在一起)。
标签: c# .net inheritance interface