Take for instance the SqlBulkCopy.WriteToServer() method. One of the overloads takes an IDataReader as the parameter. My question is, what’s the benefit/advantage to passing an interface to a method instead of the object instance itself?
Take for instance the SqlBulkCopy.WriteToServer() method. One of the overloads takes an IDataReader as
Share
You can have many possible implementations for that one interface. Its better to depend on an abstraction (in this case an interface) than an actual concrete class – this allows much better flexibility and testability.
This also puts the focus on what is really required by the
WriteToServer()method – the only thing its contract requires is for the caller to pass in any instance of a concrete class that provides the methods / properties declared by theIDataReaderinterface.