aspnet examples question

R

rodchar

hey all,

the following code snippet was in a tutorial at asp.net regarding DataList
examples and this was used as the datasource:

ICollection CreateDataSource() {
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("StringValue", typeof(string)));

for (int i = 0; i < 10; i++) {
dr = dt.NewRow();
dr[0] = "Item " + i.ToString();
dt.Rows.Add(dr);
}

DataView dv = new DataView(dt);
return dv;
}

my question why not make the return type a DataView instead of this
ICollection interface?

thanks,
rodchar
 
S

sloan

You need to get a book on basic OO principles.


Basically, somewhere DataView is an ICollection or the code would not work.

By returning the interface, you're protecting yourself in the future,
because you could completely swap out the implementation of
CreateDataSource() with another (or any) object that implements the
ICollection interface.

Thus you future proof yourself.

That's 1 cent explanation for the OO concept....in about $1,000 worth of
information.
 
P

Peter Bromberg [C# MVP]

Perfect.
--
--Peter
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com



sloan said:
You need to get a book on basic OO principles.


Basically, somewhere DataView is an ICollection or the code would not work.

By returning the interface, you're protecting yourself in the future,
because you could completely swap out the implementation of
CreateDataSource() with another (or any) object that implements the
ICollection interface.

Thus you future proof yourself.

That's 1 cent explanation for the OO concept....in about $1,000 worth of
information.





rodchar said:
hey all,

the following code snippet was in a tutorial at asp.net regarding DataList
examples and this was used as the datasource:

ICollection CreateDataSource() {
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("StringValue", typeof(string)));

for (int i = 0; i < 10; i++) {
dr = dt.NewRow();
dr[0] = "Item " + i.ToString();
dt.Rows.Add(dr);
}

DataView dv = new DataView(dt);
return dv;
}

my question why not make the return type a DataView instead of this
ICollection interface?

thanks,
rodchar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top