Reputation: 41
In my domain model diagram, I have a class Area that is defined by multiple sensors (eg:temperature sensors), but each sensor can be on one area at a time. As I can move the sensors, I can change the sensors to another area, and in the ultimate case delete the area (because an area needs sensors to exist).
Knowing, Area has already and attribute data:Data. How can i keep track of previous Areas?
eg:
time=0 - Area A has sensors 1,2,3
time = 10- Area A has sensors 2,3
time =20- Area A has sensors 3
I want to be able to go to previous states of the instance, and check which sensors belonged to the area at a certain time t.
Current diagram:
Upvotes: 2
Views: 260
Reputation: 73366
The qualifier is an interesting approach. However, it requires to know the precise timestamp of the start of an Area
assignment to access the current or an historically associated area. Moreover the history goes in both direction, unlike the qualifier which is inly at one end.
For these reasons the association class would be more suitable:
The only challenge is to express the multiplicity constraint at any given time, as the association would become many to many: it’ll be more difficult to tell that there is only one area for a sensor at any given time. Programmatically (for the implementation), it’ll not be a big deal to implement this. But expressing this in OCL, taking into account possibly overlapping intervals it’s more difficult. Fortunately, as qwerty_so indicates in the comments, it’s perfectly valid to express the constraint in plain english.
N.B. additional comparison of an association class and a qualified association for similar problems, here on SE.
Upvotes: 1
Reputation: 3625
You can use a qualified association with the timestamp as qualifier. This is shown with a small rectangle at the Area
end of the association with the text t:Timestamp
in it.
PS: In your diagram an Area
can exist without Sensors
, since the multiplicity is 0..*
. You should change it to 1..*
if you want this semantics.
Upvotes: 1