我正在Microsoft Docs上研究 UOW 模式并看到以下代码
interface IStudentRepository: IDisposable
{
void SomeMethod();
}
// Interface Implementaion
class StudentRepository: IStudentRepository, IDisposable
{
public void SomeMethod(){}
public void Dispose(){}
}
现在我的问题是为什么我们要在实现派生接口的类上重新实现派生接口的父接口?例如,ISudentRepository 接口派生自 IDisposable 接口,但是当我们在 StudentRepository 类上实现 IStudentRepository 接口时,除了 IStudentRepository 接口之外,我们还实现了 IDisposable。
注意:我已经尝试了这段代码而没有再次重新实现 IDisposable 并且尝试来回转换;一切正常,因为它适用于重新实现。
IDisposable
在实现的类上指定IStudentRepository
是多余的。它根本没有效果。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句