Imagine the following code:
MyService myService = new MyService();
myService.Start();
myService.DoStuff();
The MyService class looks like this:
public class MyService : ClientBase, IMyService
{
...
}
Now I wanted to change the existing code to call this class by using its interface:
IMyService myService = GetMyService();
myService.Start();
myService.DoStuff();
Looks better, but now I get an error on the line containing myService.Start();, since this is an implementation inherited from the ClientBase base class.
What should I do now? Extend the IMyService interface and include the ClientBase interface? That’s the only solution I can think of now, but I don’t think it’s very elegant…
EDIT: The ClientBase class is the one from System.ServiceModel so I can’t change anything about this.
There is nothing wrong with interface inheritance…
Then you should be allowed to use your existing code:
An alternative solution would be to make your MyService class implement IClientBase and then just do a cast:
However, I think youl agree the first solution is much better.