Search code examples
umlmodelingclass-diagramsequence-diagram

Modelling time based attributes and methods in UML


I want to model a method which occurs when a specified time has elapsed and an attribute which disappear with class and sequence diagram.

Here is the situation: Workers are working in a factory where they use machines. Each machine can be used by 0-10 workers. Every machine has a repair time limit whereupon the workers have to repair it. It also has a time limit whereupon if the workers miss the repair, the machine explode and the worker or workers dies (bigger then the first one). There are different machines. Some of them have longer time limit, some of them have shorter. All machines are machine oiled which lasts for a while and it gradually loses its strength until it disappears. This value the same for all machines.

My class-diagram: enter image description here

I saw this solution for the repaireTime and explodeTime can handle with qualifires counting the elapsed time, but I do not see how does a tick increase the qualifiers value. Is it behave like an attribute like this? squence

At last, how does the machine oil disappear works? It is just an attribute what must be deleted but I do not understand where to count the elapsed time for this and then delete it.

EDIT: enter image description here enter image description here enter image description here


Solution

  • Your sequence diagram appears to be fine.

    Your class diagram is however misleading:

    • The class diagram is a structural diagram, and not a behavioral diagram. SO you don't really care for elapsed time unless it appears in a property or an operation.
    • The navigation arrow between Machine and Timer does not facilitate the proposed sequence diagram, which assumes that the Timer knows to find the Machine.
    • Isn't the association with worker end and with works end not the same associations in the end, if considered at the general level?
    • The qualifier for the elapsed time is not correct.

    For the time based association between Machine and Worker, you could consider making this a many to many association, with an association class defining the time-slot (start and end time, from which you can calculate the duration). You may find here some information about how to work with timeslods (although you do not need the additional constraints mentioned in that other question).

    Edit: review of your updated diagrams

    The class diagram looks better. Some advices:

    • Class and Subclass1 are probably Machine and E1 ?
    • Is the duration association class specific to Subclass or is it general for any Class? In the latter case, you should draw it between Worker and Class. It is not necessary to repeat it for Subclass, since the specialisation automatically inherits the associations, properties and operations of its generalisation.
    • If the Timer has to send messages to objects? The dependency relation therefore seems misplaced. Shouldn't it then have an association with the classes to the instances of which it shall send messages?
    • How does the Timer know about new Duration objects ? Does it need to know Duration objects or couldn't it send ticks to the machines, which would forward the ticks to the durations?

    On the sequence diagrams, and independently of the impact of the above-mentioned advices, it is important to realize that lifelines do not represent classes, but objects that belong to the classes. The class-names should therefore be preceded by a : or an object name and a :.

    The second diagram would be integrated in the first diagram if you'd go for the tick forwarding. Nevertheless, if you'd keep it, you should ask yourself how a Duration could check if elapsed_time==timeExplode since timeExplode is a property of the machine and not of the duration.