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
andProduct
translates as a list ofProducts
. For example in JavaOrder
would have a member of typeList<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 theOrder
side and a ">" (not a triangle) on theOrderDetail
side.If you decide to use
Product
instead ofOrderDetail
then you should have an "agregation" which has a white diamond shape.The difference is that a composition means
OrderDetail
has no meaning outside anOrder
whereas agregation means thatProducts
can exist by themselves outside anOrder
.