umlclass-diagramclass-designvisual-paradigmibm-rational

Consequences of misdiagnosis / false identifying of the relationships types in the class diagram


I read a lot of documents about relationships in the class diagram but I'm still hesitant about some relationships.

  1. My first question is to identify the type of below relationship :

enter image description here

as you could see in the above image I have NetworkAgent class which includes NetworkUDPReceiver for listening and receiving and NetworkUDPSender for sending packets.

I know Aggregation is a whole-part structure as parts could be shareable and Association used when a class has a reference to another class as a member in the non-whole-part structure.

in the above example, I see a whole-part structure and shareable parts. does my opinion is right? do you see Aggregation?

  1. My second and more important question is what would happen if I choose the wrong relationship? I know the right answer may depend on my application or problem concept.

For example, if the correct answer is Association, what would happen, or what are the consequences if I choose Aggregation incorrectly? (and vice versa)

update question: Bruno correctly informs me the position of aggregation sign <> on the above image is incorrect and should be reversed.


Solution

  • This diagram is misleading

    Fortunately, NetworkAgent has an embedded hint to help us sorting things out: two properties, receiverAgent and senderAgent, which are of type NetworkUDPReceiver and NetworkUDPSender respectively:

    So this corresponds almost exatly to the associations you have circled, with one significant exception: the aggregation which is wrong.

    The thing with the aggregation

    The white diamond is indeed meant to describe a part-whole relationship (with the diamond on the side of the whole). But UML let the semantics open, and de facto, there is no advantage of using it rather than a normal association. So, if you make the diagram, the best advice is to avoid it.

    I would moreover challenge you to prove that there is a part-whole relation between an agent and sender/receiver: a sender is not a part of the agent. A sender is just associated to an agent.

    Some modelers misuse the UML aggregation to represent systematically object composition. This is not fundamentally wrong, but mixes implementation concerns with design concerns. Such modelers would indeed use aggregation here, but would put it on the side of the agent.

    More on this topic, with in-depth argumentation additional references, here.

    Conclusion

    The best is to remove the aggregation from the diagram. If you decide that you want to use it for object-composition, then move the diamond to the other side.

    More generally: if you use an association instead of an aggregation, there's no impact. If you use aggregation instead of an association, it might be misleading, but in general without practical consequences.