是否允许类在C#中实现接口和其他私有方法?

Cic*_*ami 2 c# interface private-methods interface-implementation

我有以下界面:

interface IExcelServices
{
    Dictionary<string, string[]> FilterFields(Dictionary<string, string[]>  excelContent);
    Dictionary<string, string[]> ParseExcelFile(string path);
}
Run Code Online (Sandbox Code Playgroud)

这由以下类实现:

public class ExcelServices : IExcelServices
{
    public Dictionary<string, string[]> FilterFields(Dictionary<string, 
       string[]>  excelContent)
    {
        //somecode
    }

    public Dictionary<string, string[]> ParseExcelFile(string path)
    {
        //somecode
    }

    private void ReleaseObject(object obj)
    {
        //somecode
    }
Run Code Online (Sandbox Code Playgroud)

}

我的代码编译没有任何问题,但我想知道是否添加一个不在接口定义中的私有方法(或通常任何方法)是一个很好的OO编程实践.

谢谢
弗朗切斯科

Tho*_*que 9

当然可以在实现接口的类中添加其他成员.接口只是一个合同,它指定了类必须实现的内容,但它也可以添加它需要的任何成员(实际上大多数类都有更多的成员,这些成员在接口中声明了这些成员)