Search code examples
umlaggregationrelationships

UML Relationships. Aggregation


I have a problem with my UML diagram and I'll be happy if you help me. I have relationships like

Object A (1)<>----(0..*) Object B

Object B (1)<>----(0..*) Object A

and I'd like to unite them. How can I do it? Thanks a lot.


Solution

  • Can you please define the term "unite them"? What exactly would you like to achive? An example could probably help.

    Meanwhile, I can try to guess and give you two possible solutions. Maybe they help you to rephrase your question or even to find the solution:

    enter image description here

    In the Solution 1, I've just made a single relationship that describes both of yours. This can be used if there is only a single and clear criterion of the linkage between the objects. A typical n..m relationship. Objects A will each hold a collection of related objects B and vice versa.

    • For example a Person (A on the diagram) can join several Clubs (B) and a Club can have several members - there is only one logical relation behind this situation - membership.

    Solution 2 is where there are actually 2 different ways to relate between those elements, each one 1..n. So, A holds a collection of Bs and B holds collection of As, but they are unrelated.

    • Extending the same example - a Person (A) can join only 1 Club (B) and a Club can have many members and hold their reference (col_a on the diagram). In the same time, a Club can have only 1 owner, and a Person can own several Clubs (col_b). Here we have two different logical relations - membership and ownership.

    Of course, other multiplicities and navigabilities are possible, this is just an example to give you an idea.

    Does one of these situations sound like yours?

    UPDATE (after the 1st comment):

    So, here is the updated solution 1:

    enter image description here

    This is an aggregation used here, and this is more a Group-member relationship. It suits perfectly the description of my first solution up there. Members (B) can be "shared" between the Groups (A) and Gruop does not have any special control over their lifetime.

    The real Whole-part relationship would employ composition instead of aggregation (visually depicted with a black diamond, instead of a white one). Its semantics it that Whole object has a full control over the life of the contained objects (parts). In consequence, the Parts cannot be shared between several Wholes and must be destroyed if the Whole itself is destroyed.

    Now you just need to find out which situation describes your problem the best, pick-up on of this solutions and eventually fine tune the multiplicities.