简体   繁体   中英

Association, Aggrgation and Composition in UML Diagram

So I have some question about the association, aggregation and composition in UML diagram. Here is some scenarios :

  1. Product review rating composition to product review. This means that for each product review rating MUST HAVE product review? If product review doesn't exist, rating for review doesn't make sense.

  2. Customer NRIC associate to cart and order. We cannot use aggregation because if customer does not exist, cart and order cannot exist also.

Can somebody please help me check if my relationships are correct? Is it good to link all your tables with association because I kind of confused on aggregation and association. I do not know when to use that.

在此处输入图片说明

Correct me if I am wrong. Thanks in advance.

Take a look at this class diagram example for composition: 类图1

Composition declares an ownership associationship. Person owns Leg and Hand. Or other way around, Hand belongs to Person.

Now ask yourself how would you describe each relationship in your model. If you would say Product review rate owns a Product review or Product review belongs to a Product review rate , then your diagram is OK. If the ownership has the opposite direction ( Product review rate belongs to Product review , then the diamond must go to the other side of the association.

The same thing applies to aggregation. If the association somehow declares an ownership, then the diamond must go to the side of the owner class.

The difference between aggregation and composition is that objects owned as composites can't be created without their owner, so usually they are created by their owner. These objects are destroyed when their owner is destroyed, they couldn't be used by another owner after their owner dies. Objects owned by an aggregation association can be created without their owner and possibly could outlive him and serve another owner.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM