There are many answers, and they are all right, since an explicit implementation of the interface is the answer to your problem.
I will try to clarify the motivation for this design with a somewhat confusing example:
Say I have an interface for people who are starting up (with possible implementations like LongDistanceRunner , Jogger , MarathonMan , etc.)
public interface IRunner { void Run(); }
and an interface for devices that can be turned on and running (with possible implementations of BathTub , Application , Dishwasher , etc.)
public interface IRunnable { void Run(); }
Now I want to create an interface for IMusicallJogger (implementations such as JoggerWithIpod , BoomBoxJogger , etc.)
public interface IMusicalJogger : IRunner, IRunnable {} public class BoomBoxJogger : IMusicalJogger {
Now when I say bbJogger.Run() , what should my object do? Should he start running around the park, or should he turn on the boombox, or both, or something else? If I implement both a class and callsite, it may be obvious that I want my joggers to do both, but what if I control only callsite? But what if there are other implementations of the interface that do something else? And what if my runner starts running around the park when he is used in a context where he is seen as a device (via casting).
Where the explicit implementation of the interface is implemented.
I need to define my class as follows:
public class BoomBoxJogger : IMusicalJogger { void IRunner.Run()
and then when I call, I have to indicate which aspect of my jogger I want to use:
BoomBoxJogger bbJogger = new BoomBoxJogger(); ((IRunner).bbJogger).Run(); // start running ((IRunnable).bbJogger).Run(); // blast the boombox //and of course you can now do bbJogger.Run //running while listening ((IMusicalJogger)jogger).Run(); //compiler error here, as there is no way to resolve this.
Hope I helped clarify the concept.