I've created a library for an online store and I'm having a bit of a design issue with a couple of objects that are widely used within the library, namely Product, but also others such as Customer.
For Product I have "Product", "ProductList", and "ProductInfo". This works fine.
A number of other objects also require product information. For example BasketLine and OrderLine need to know the product name, image, whether it's in stock, etc. Other objects for product reviews, product bundles, etc also need to load product information.
Until now I have always used joins in the sql statements to link to product information in read only lists. For editable objects I have added a non-serialized property to load the Project object and access the properties, such as:
[NonSerialized]
Product product;
public ProductName
{
get
{
if (this.product == null)
{
this.product = Product.GetProduct(this.productId);
}
return this.product.Name;
}
To me this seems really inefficient as loading the product object additionally loads a number of child collections.
What I think I want to do is create a parent readonlybase ProductSummary class that reads in the property information as well as loading a child read-only collection of product variants (such as different sizes/colours etc).
Then, with the other objects I can create a similar nonserialized member and lazy load it with ProductSummary.GetProductSummary(productId);
I'm not completely confident that this is the best way to go about it, so I'm wondering if anyone else has come across this and has any good ideas. It's vital that the library is efficient and doesn't carry out unnecessary processing.
Thanks.
UK Daaarn Saaarf