I know it is very general question but I think it would be very beneficial for less experienced programmers to get clear answer.
Scenario:
Let say I have MyClass
which is implementing interfaces IMembers1
, IMembers2
, IMembers3
. MyClass
also contains members which are not defined in any of those interfaces.
Question:
Is there any benefit in using f.e. IMembers2
reference to access IMembers2
members in MyClass
instance instead accessing them by simply using MyClass
reference.
If I have instance of type which is unknown at compile time but I'm sure it will implement IMembers2
interface I would of course use IMembers2
reference to access its members. Lots of code examples and tutorials are teaching to use f.e. IEnumerable<T>
reference to access list collection in heap instead of using List<T>
reference.