The whole point of interfaces is to provide... well, an interface to whatever module (I use "module" in a broad sense here) so that calling code will not have to worry about how this particular interface is implemented.
As for "How can IDictionary
interface be initialized", this is technically not correct. What can be initialized is a variable, whose type is IDictionary<T, V>
. Sure enough variables have to be initialized, but that's usually hidden from the "client code".
IDictionary
is not very representative, however. Rather, consider an IDataReader
interface. You've surely dealt with ADO.NET, so this should look familiar:
public Foo PopulateFromDataReader(SqlDataReader dataReader)
This particular method is tightly coupled to an SqlDataReader
, so you'd have to rewrite it for it to support, say, Access or Oracle or MySQL or Firebird or whatever. In other words, you depend on implementation.
Now consider:
public Foo PopulateFromDataReader(IDataReader dataReader)
This method can be used with whatever class that implements IDataReader
, which means with basically any ADO.NET-compatible data provider.