method type ICollection returns Dataview

  • Thread starter Thread starter Janus Knudsen
  • Start date Start date
J

Janus Knudsen

Hello :O)

Im in the process of learning asp.net, and i'm reading a nice book. But then
suddenly i came across this:

public ICollection DataLoad()

{

DataTable dtEmployee = new DataTable();

DataRow drEmployee;


dtEmployee.Columns.Add(new DataColumn("emp_id",
System.Type.GetType("System.Int16")));

dtEmployee.Columns.Add(new DataColumn("emp_name",
System.Type.GetType("System.String")));



drEmployee = dtEmployee.NewRow();

drEmployee["emp_id"] = 1;

drEmployee["emp_name"] = "E.E. Smith";

dtEmployee.Rows.Add(drEmployee);


dvEmployee = new DataView(dtEmployee);

return dvEmployee;

}



The method type is ICollection but it returns a DataView - what's the
purpose of that? The caller then casts it as a DataView in order to use it,
is't a normal approach or? And what about overhead with all that
typecasting?



Kind regards
 
Hi,

Since DataView implement ICollection therefore the function can return
DataView. the idea behind such code is flexibility. Every function can
call that method, expect ICollection as result and work against
ICollection defined methods and properties. This way of programming
enables DataLoad users to work with that function even if you change
function implementation, because programmers works against Interface


Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)52-8888377


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Back
Top