I've seen the following code layout reading forums and other blog posts and adapted in order to ask a few questions.
public interface IService<T>
{
int Add(T entity);
void Update(T entity);
}
public abstract class ServiceBase<T> : IService<T>
{
public int Add(T entity) { ... }
public void Update(T entity) { ... }
}
public interface ICarService : IService<Car>
{
}
public class SomeBaseClass : ServiceBase<Car>, ICarService
{
public int Add(Car entity);
public void Update(Car entity);
}
What I don't understand is the benefit of having the abstract class implmenting the interface. To me it just feels a bit repetitive and I cannot understand the benefit of having an abstract class implementing the interface.
- Why doesn't the abstract class
ServiceBase<T>
just define as is without the need to inherit the IService interface? Is this doubling up the code? - Why must the
SomeBaseClass
also implment theICarService
? Shouldn't the ServiceBase be sufficient?