I have the following code example:
public interface IRepository {
// Whatever
}
public class SampleRepository : IRepository {
// Implements 'Whatever'
}
public class NHibernateRepository : IRepository, IDisposable {
// ...
public void Dispose() { ... }
}
Now - is that really bad? I'm not sure, but this seems to be pretty the same as not marking the destructor of the base class virtual in C++
.
I don't want to make the IRepository
interface implement IDisposable
, because that would bring unwanted complexity and bunch of classes which would also have to implement IDisposable
.
How should this case be handled?
I'm sure this can happen to any type hierarchy - when one of the derived type has to manage disposable resources.
So what should I do - pull the IDisposable
up to the very first interface or leave it as it and hope user would distinguish disposable and non-disposable repositories?
Thank you.