Search code examples
design-patternsclass-designuml

UML Class Relationships


I would like to confirm whether I am on the right track when identifying common UML class relationships. For example, is the relationship between:

1 a stackoverflow member and his/her stackoverflow user account categorized as a composition relationship or an aggregation relationship? At first I thought it was an association because this member "has a" account. However on second thought, I am thinking its composition because each "part" (user account) belongs to only one whole (user) at a time, meaning for as long as I am logged into stackoverflow, I have to use this one and only account until I log off. If I log back onto stackoverflow with a different account then its composition again. Do you agree?

2 a database and a person's user account an aggregation relationship? I think so because 1 database (the whole) can store 0...* number of user accounts (the parts) but another database can store the same user accounts.

Finally, can anyone recommend a website that specializes in designing code using UML? Thanks in advance


Solution

  • A stackoverflow member and his/her stackoverflow user account categorized as a composition relationship or an aggregation relationship ?

    Well, Let's see the following diagram

    • Aggregation

    Transplant is possible

    Aggregation

    If i miss some Finger, so other Hand can receive my missing Finger


    • Composition

    Transplant is impossible

    Composition

    If i miss some Finger, so no other Hand can receive my missing Finger

    Both Aggregation and Composition, A Finger (The part) has its lifecycle bound to that of its owning Entity instance (if i miss my Hand, so its Finger will be missed) So, If i remove my Stackoverflow Member, its UserAccount will be removed.

    Back to your question: Your UserAccount, although has its lifecycle bound to its Stackoverflow Member, if missed, can be assigned to another Stackoverflow Member ??? I do not think so. So, it is Composition