I am Business Logic component to enable Customers can place online orders. So far my simplified business logic look like this:
public class Product
{
public int productID { get; }
public string name { get; set; }
//other properties here like address and such
}
public class Order
{
public int orderID { get; }
public Customer customer { get; set; }
public List<Product> OrderItems { get; set; }
//other properties go here
}
List of Products will not support orders that contain products of multiple quantities. How do I add that support here? How would I call it from client side?
Don’t use a
List, use aDictionary<Product,int>, where theintparameter is the quantity, orDictionary<int,int>, where the firstintis the product id and the second is the quantity.You can always override
.Equalsfor yourProductclass to be implemented in terms of your product id, so you’re still using anintto define a product, but it may make things a bit simpler down the road (or if you ever need to change that).