I got a bit confused designing the classes for a shopping cart application.
A ShoppingCart has a set of ShopCartItems, each of which contains an instance of a Product and the quantity. The ShoppingCart instance is always stored in the session.
As shown below, Invoice has a reference to the Customer, a set of ShopCartItems, date, invoice number, and total amount. How should I design the Order class? I'm thinking it should also contain the Customer, ShopCartItems, and date.
I'm worried about creating redundant classes, but I want the functionality of letting a user cancel an order, so that requires storing them in the DB.
public class Invoice {
private Long invoiceId;
private Customer customer;
private Set<ShopCartItem> shopCartItems;
private Date invoiceDate;
private int invoiceNum;
private float totalAmount;
private boolean isProcessed;
...
}
class Product{
private String name;
private double price;
...
}
class ShopCartItem{
private Product product;
private int quantity;
...
}