我有一个A,B和C类通用的接口.但是现在我需要添加两个方法,它们只适用于B类,不适用于A类和C类.那么,我是否需要将这两个方法添加到公共接口本身并在A和C类中抛出未实现的异常,或者有更好的方法吗?
interface ICommon
{
Method1;
Method2;
Method3;
Method4;
}
Class A: ICommon
{
Method1;
Method2;
}
Class B: ICommon
{
Method1;
Method2;
Method3;
Method4;
}
Class C: ICommon
{
Method1;
Method2;
}
Run Code Online (Sandbox Code Playgroud)
提前致谢
如果这些方法对于其他类(不仅仅是B)是通用的:
让B扩展另一个接口
interface ICommon2
{
Method3;
Method4;
}
class B : ICommon, ICommon2
{
Method1;
Method2;
Method3;
Method4;
}
Run Code Online (Sandbox Code Playgroud)
如果这些方法仅针对B:
class B : ICommon
{
Method1;
Method2;
Method3;
Method4;
}
Run Code Online (Sandbox Code Playgroud)