views:

34

answers:

1

Given the following code:

public interface IExample { ... }
public abstract class BaseExample: IExample { ... }

public class ExampleA : BaseExample { ... }
public class ExampleB : BaseExample, IExample { ... }

Are there any benefits or drawbacks in writing code like ExampleB?

My guess is that re-specifying IExample in the derived class ExampleB is redundant. Am I wrong? I thought derived classes implicitly inherit all interfaces implemented by their base types?

We're currently writing things like ExampleB but its starting to bug me how verbose some of our derived class implementations are becoming. Another developer here says its good because it declares the intentions of the class better and make the code more readable. But to me its just getting messy.

A: 

It will be redundant yes.

Another thing you should be cautious about, is that when a single implementation starts implementing lots of interfaces, it'll most likely hurt the single responsibility principle. It's hard to say when/if this is the case for you, and it also depends a lot on the interfaces.

Sander Rijken