What is the correct design for signals in a UML class diagram?

Viewed 332

This is something that shouldn't be hard to find, but I searched for hours and couldn't find a definitive answer.

Following problem:

We have two classes. An active class "sensor" and a "device".

When the sensor detects something, it should inform the device about it. All of this must be defined in a class diagram.

My idea was that the sensor sends out a signal, which is then received by the device. Easy, right? I couldn't find the definitive correct way to model this!

First of all, how does a class sends a signal in a class diagram? I thought about an directed association from sensor to signal with the stereotype "send". Is that the right way to model it?

And how to show that the device received exactly that message? I know there is an compartment for receiving signals, but that can be overlooked easily. Is it allowed to create a direct (graphical) association between signal and receiver?

1 Answers

As you hopefully know by now, UML diagrams are in general grouped in two main categories: static and dynamic. They respectively represent, as the names suggest the information about the elements such as data structures, system components and so on (static) and interactions and system behaviours, functionalities and interactions.

Class diagram is one of the static diagrams so it does not offer you a straightforward way of showing the signal exchange specifically between two (or more) classes. You may model a fact that a specific class send a signal as well as that receiving a signal triggers behaviour of a class, but it does not indicate the direct connection between the classes. For that you will have to refer to dynamic diagrams and signal exchange can be depicted e.g. on activity diagram, sequence diagram and communication diagram.

In the class diagram the signal itself is depicted as a classifier, i.e. a rectangle. It has to have a stereotype <<signal>>

enter image description here

The reception can be depicted in the ... section of the classifier (especially class) in a form of Reception with the name matching the Signal name preceeded with a <<signal>> stereotype:

enter image description here

I did not find in specification any specific notation (within Class diagram) to indicate that a particular Class can send a signal. You can always use a Dependency (i.e. a dashed arrow with an open head) - as the weakest kind of a relationship. Using a stereotype <<send>> on that Dependency wouldn't do harm either.

I would discourage depicting the relation to the Signal as an Association as it would suggest the Signal being a Feature (efectively a Property) of that Class - and that is not true.

Related