Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UML Class diagram for Chat

I'm designing a UML class diagram for a messaging app.

Each Chat must have exactly 2 Users, and each User can be part of multiple Chats. I originally modeled this with a composition from User to Chat.

However, I'm not sure if this is correct.

My goal:

  • A Chat is between exactly two Users.
  • Users are not owned by the chat and can exist independently.
  • If both users are deleted, their chat is also deleted.

Should I be using a normal association instead of composition here? What’s the best way to represent this in UML?

Thanks in advance! UML

like image 646
jenepix Avatar asked Oct 31 '25 14:10

jenepix


1 Answers

each User can be part of multiple Chats

so you have to replace the multiplicity 1 by * (or 0..* if you prefer) on the composition User / Chat

Should I be using a normal association instead of composition here

pro of a composition : the composition indicates that If both users are deleted, their chat is also deleted

cons of a composition : the main is a composite aggregation is a strong form of aggregation that requires a part object be included in at most one composite (c.f. formal/2017-12-05 §9.5.3 Semantics page 112), and also independentely of the multiplicity a composition is first an agregation and a Chat is not a part of a User

But notice the multiplicity 2 on the association User / Chat implies a Chat needs 2 associated Users and cannot exist without them, restricting its life.

So for me you must use a normal/simple association :

enter image description here

Out of that, are you sure a Message must know in which Chat it is ? If no Chat <*>-1----*-> Message is enough :

enter image description here

like image 85
bruno Avatar answered Nov 03 '25 13:11

bruno



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!