Simple question:
What would you rather do?
public class FooRepository
{
public Foo GetById(int id)
{
Foo foo = null;
using (IDataReader data = /* Get Foo's data */)
{
// Let the Foo object set it's own fields using the data object
foo = new Foo(data);
}
return foo;
}
}
Or...
public class FooRepository
{
public Foo GetById(int id)
{
Foo foo = null;
using (IDataReader data = /* Get Foo's data */)
{
// Let the Repository class set the Foo object fields
foo = new Foo();
foo.Id = Convert.ToInt32(data["FooID"]);
foo.Name = data["Name"].ToString();
}
return foo;
}
}
Assuming you can't use an ORM (NHibernate, L2S, EF) to handle this for you and that you will need to create Foo in other methods of the repository.
Any explanation will be welcome!