UML Class Diagrams for Order and Products

class-designclass-diagramuml

I have a class diagram that is like this:

< Order > (1) CAN HAVE (M) < products >

But therefore Order has the following:

Order_Id
Customer_Id
Order_date_day
Order_date_month
Order_date_yeah

But I do not know how it would handle the Products? Because, I couldn't have ProductID because that would mean that each item in this class would have to have a separate instance for each product (E.g. someone ordered 100 products, but only placed 1 order).

Could I have an Product object in class Order? If so, how do I represent that in UML?

Best Answer

The one-to-many relationship between Order and Product translates as a list of Products. For example in Java Order would have a member of type List<Product>.

But I recommend having an OrderDetail class instead because you will soon find that you have to have and amount or quantity of the product, and it doesn't belong in either Order or Product.

EDIT:

In UML Order would have a "composition" which is a line with a black diamond shape on the Order side and a ">" (not a triangle) on the OrderDetail side.

If you decide to use Product instead of OrderDetail then you should have an "agregation" which has a white diamond shape.

The difference is that a composition means OrderDetail has no meaning outside an Order whereas agregation means that Products can exist by themselves outside an Order.