Skip to content

Instantly share code, notes, and snippets.

@kkozmic
Created September 30, 2010 04:36
Show Gist options
  • Save kkozmic/604033 to your computer and use it in GitHub Desktop.
Save kkozmic/604033 to your computer and use it in GitHub Desktop.
public interface IFoo
{
void Foo();
}
public class Base:IFoo
{
public void Foo()
{
}
}
public class Inherited: Base,
IFoo // <-- why/when would you want to do it?
{
}
@UweKeim
Copy link

UweKeim commented Sep 30, 2010

Never, it is redundant. ReSharper suggests to remove line 14.

@augi
Copy link

augi commented Sep 30, 2010

If you would use reflection then under certain circumstances it could be handy.

@augi
Copy link

augi commented Sep 30, 2010

And if you would like to implement the interface explicitly.

@ploeh
Copy link

ploeh commented Sep 30, 2010

I can't think of a single reason to do this. Even if you can come up with some technical corner case where it may seem necessary (e.g. explicit interface implementation) it violates the Principle of Least Astonishment, so is a design smell. If you need to override the behavior of Foo, make it virtual in Base. If you don't own Base, create a Decorator instead of deriving from Base.

@augi
Copy link

augi commented Mar 11, 2011

Yes, this is design smell and I would never use them. I wrote just technical reason why someone would want to do it :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment