Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / April 2008

Tip: Looking for answers? Try searching our database.

returning interfaces

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike P - 17 Apr 2008 11:56 GMT
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?
Lasse Vågsæther Karlsen - 17 Apr 2008 12:10 GMT
> 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

Ignacio Machin ( .NET/ C# MVP ) - 17 Apr 2008 15:26 GMT
> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.