I’m not sure if I’m overthinking this but in the past, I’ve done something like this when declaring a class:
IMyService myService = new MyService();
Jumping into myService will take you to the IMyService interface.
However, doing the following will (obviously) take you to MyService.
var myService = new MyService();
Which is considered the ‘correct’ usage, or is this another example of “What’s your favourite ice cream flavor?”?
I’ve looked at the most relevant question but it doesn’t really answer my scenario.
Well, it depends. Do all the public members of your
MyServiceclass come (exclusively) from the implementation of theIMyServiceinterface? Or there are some extra public members (perhaps from the implementation of another interface)? If so, the second “flavor” will allow you seeing these extra members, while the first one will not.On the other hand, if you are using interfaces, I would say that the “correct” usage is obtaining the type instances from a dependency injection engine or from some kind of factory class or method, but I guess that’s outside the scope of this question.