UML – Class Diagrams Order -> Products

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?

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.

4

Normally, you have two classes in your diagram: Order and Product.

As an order usually means that the customer has ordered 1 or more (1..*) products, you model this by creating an association from the class Order to the class Product.

This coincides with adding a collection of Product instances to your Order instances, i.e. most code generators will give you a Order.getProducts() method or something similar. In fact, you can add such an association explictly as an attribute to the Order class. Some tools hide this fact, others allow you to see this distinction clearly (f.ex. Papyrus).

I do not know how it would handle the Products

Assuming that you are modeling this to generate RDBMS tables, you would generally use 2 separate classes. The ‘child’ class would have the Product attributes plus the Product_Id acting as a ‘foreign key’. The other class is your Order class.

The diagram in the answer of @Esther Fan – MSFT in UML-arrows-pointers-explanation shows more than what you want in fact, however, on a class level its what you want. Just replace the word “Order_Item” by the word “Product” in the class diagram and ignore the other classes not related to your case.

The MSDN link provided within that answer may also be useful for you.

An important business rule you need to consider is whether an Order occurence is meaningful without Products or not. The diagram in the link above assumes a composition association between Order and Product (Black diamond), this may or may not be your case, so please check.

It is also common to have a class for a requesting entity and a product reference entity shown but you did not ask for those. As an example, have a look at: Simple Class Diagram.

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).

The above situation is not a problem. Each of the products would use the FK column (Order_Id). The value in that column would be the same for the 100 products.

Could I have an Product object in class Order?

Yes, but this will not replace the 1-M pattern existing here. See a UML representation sample here: Inner-Internal Class.

Note that in cases, you need programming data structures for representing collections of data in your code that is different from the data structure you use to represent the same information in the database if you use RDBMS from an OO application.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật