-
Interfaces and methods..
I have a question... If I declare a datareader and give it some data
dim rdr as OleDBDataReader = mycommand.executereader()
if I then create a new customer class
dim mycustomer as new Customer(rdr)
and the customer is declared like this
public class Customer()
public sub new(byval rdr as IDataReader)
'do something
end sub
end class
whats the point of using an Interface as a parameter? Why not just pass the datareader object itself? After all, I have already set it to oledbdatareader, so the purpose of using the interface is already defeated, yes?
As I see it, it could be useful to use the interface if I had no clue what kind of datareader I was talking to... then an iterface is handy. But now I could just go along with the oledbdatareader itself...and forget about the interface
Can anyone clarifyif why an interface is used in this case, and give some further information about the whole subject...
thanks
Henrik
-
In that instance of use yes it is using an oledbdatareader but the code in the constructor should be made to work with any type of datareader since it accepts the interface. Then you could mix and use odbc or sql datareaders at anytime. The class doesn't know how it will be used so it can use the interface to work with any of the datareaders. What if someone else uses this class and doesn't want to use oledb?
-
thanks.. It is these kind of stupid questions that pop out when you have had too much coffee ;) Of course you are right...
thanks!!!
Henrik
ps Im the only one in my company working with OO... I had no one else except the vb forums to get my head screwed on straight ds