I would like to know what is the best pattern when returning objects from custom collection classes. To illustrate my problem, here is an example:
I have a Customer class:
public class Customer
{
//properties
//methods
}
Then I have a customer collection class:
public class Customercollection: Collection<Customer>
{
public Collection<Customer> FindCustomers()
{
//calls DAL and gets a Collection of customers
Collection<Customer> customers = DAL.GetCustomers();
return customers;
}
}
Now, an alternative version of this method can be:
public class Customercollection: Collection<Customer>
{
public Collection<Customer> FindCustomers()
{
//calls DAL and gets a Collection of customers
Collection<Customer> customers = DAL.GetCustomers();
foreach(Customer c in customers)
this.Add(c);
return this;
}
}
I would like to discuss Which one is the better approach? And is there any other approach better than two above two?