我基本上IFoo
在 Inherited 类中定义了两次。这会导致一些不可预见的后果吗?
interface IFoo {
...
}
interface IBar : IFoo {
...
}
class Base : IFoo {
...
}
class Derived : Base, IBar {
...
}
我想要IBar
继承的原因IFoo
是我可以按Derived
原样工作IFoo
而不必强制转换它。
if (Derived is IBar)
// Do work
如果它不继承,我必须强制转换它。这使得使用更加复杂,并且该类的用户可能不理解这IBar
只是IFoo
.
if (Derived is IBar)
Derived as IFoo
// Do work
这是不好的做法吗?这个问题还有哪些其他解决方案?