I read a lot of documents about relationships in the class diagram but I'm still hesitant about some relationships.
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?
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.
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:
NetworkUDPReceiver
with the name receiverAgent
on its side, and one with NetworkUDPSender
with the name senderAgent
on its side.So this corresponds almost exatly to the associations you have circled, with one significant exception: the aggregation which is wrong.
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.
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.