> In some of the code I am looking at on a sample website, a lot of
> methods are returning interfaces such as IDataReader instead of a plain
> DataReader. Why would you want to do this?
>
> *** Sent via Developersdex http://www.developersdex.com ***
Because then the implementation can return an object that looks like a
IDataReader and behaves the way it is supposed to, without actually
having to inherit from DataReader.
Interfaces are useful for making your own classes in your own class
hierarchy pluggable into some other kind of class hierarchy which has
nothing in common with yours.

Signature
Lasse Vågsæther Karlsen
mailto:lasse@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3
> In some of the code I am looking at on a sample website, a lot of
> methods are returning interfaces such as IDataReader instead of a plain
> DataReader. Why would you want to do this?
>
> *** Sent via Developersdexhttp://www.developersdex.com***
Hi,
Because you do not care about the actual type being returned, you do
not care if it's a SqlDataReader or an OracleDataReader, the only
thing you care about is that it implements the IDataReader interface.
DrewCE - 18 Apr 2008 07:05 GMT
It separates the interface from the implementation.
Here is a decent explanation....
http://bytes.com/forum/thread223924.html
-Drew
On Apr 17, 6:56 am, Mike P <mike.p...@gmail.com> wrote:
> In some of the code I am looking at on a sample website, a lot of
> methods are returning interfaces such as IDataReader instead of a plain
> DataReader. Why would you want to do this?
>
> *** Sent via Developersdexhttp://www.developersdex.com***
Hi,
Because you do not care about the actual type being returned, you do
not care if it's a SqlDataReader or an OracleDataReader, the only
thing you care about is that it implements the IDataReader interface.