Russ,
The thing is, in a logical sense, you are already breaking your n-tier
separation in your data layer. If you have a method named
"GetCustomersWithSpend", then obviously you are going to return customers,
and not something else. If anything, this is a business layer function
which in turn will call the data layer.
If you really want to keep your types out of the data layer, then return
an ArrayList, and then have a proxy/wrapper in the business side, which does
this:
// In business layer.
public static IList<Customer> GetCustomersWithSpend(Type type, double spend)
{
// Make the call to the data layer.
ArrayList objects = DataLayer.GetCustomersWithSpend(type, spend);
// Convert to an IList implementation:
List<Customer> retVal = new List<Customer>(objects.Count);
// Cycle through and add the item.
foreach (object o in objects)
{
// Add to the arraylist.
retVal.Add((Customer) o);
}
// Return.
return retVal;
}
You should use ICollection<T> instead of Collection<T>, since it will be
easier to swap out later (and there is nothing on the implementation which
isn't offered through the interface). Additionally, IList extends
ICollection<T>, and it offers an indexer, as well as being able to support
data binding easier. Because of this, I returned IList<Customer>.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"russ" <ru****@excite.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi,
We have stumbled across an issue using the type safe collection
System.Collections.ObjectModel.Collection <T> to retrieve data from our
data layer.
Say we have a customer object and want to get a type safe collection of
all customers who have spend = X
Within our datalayer we would currently have the following method
public static ArrayList GetCustomersWithSpend(Type type, double spend)
{
// use custom or mapper here
return ObjectSpace.GetCollection(type,"where spend =" +
spend.ToString());
}
However, say we wanted to use a type safe generic collection I guess we
would use this;
public static
System.Collections.ObjectModel.Collection<Customer >(double spend)
{
}
But this would break the n-tier seperation as our datalayer now knows
about the Customer type.
I guess we could still return an ArrayList from the datalayer and then
create the type safe collection in the business tier using the
ArrayList.
Does anyone have any thoughts on this?
Cheers
Russ