3

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

Tom
  • 43
  • 4
  • 1
    Your specializations seem useless as they do not change anything from `Machine`. Also the navigability and SD contradict with `Machine`/`Timer`. – qwerty_so Nov 24 '20 at 07:39
  • 1
    To enforce the remark of @qwerty_so E1 and E2 are probably not classes but instancse of Machine => they do not appear in a class diagram, if you want to show them use an object diagram – bruno Nov 24 '20 at 08:47
  • I assumed that the each different Machine has a new method which is unique. What I want to know how to appear in class diagram events like this: Tick-->oilStrong-- (and) if oilStrong==0-->deleteOil() or Tick-->elapsed_time++ (and) if elapsed_time=explodeTime-->Explode() – Tom Nov 24 '20 at 10:37
  • _has a new method_ sounds like nonsense. What would make out that uniqueness? Random behavior in a different way? – qwerty_so Nov 24 '20 at 11:45
  • The only thing that could meaningful be overridden is the`deleteOil` operation which would work differently in different speciallizations. – qwerty_so Nov 24 '20 at 12:41

1 Answers1

2

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.

Christophe
  • 68,716
  • 7
  • 72
  • 138
  • I do not understand why the qualifier is not correct if the squence seems good. Essentially I want to model elapsed time events like this on class diagram: Tick-->elapsed_time++ (and) if elapsed_time=explodeTime-->Explode() or Tick-->oilStrong-- (and) if oilStrong==0-->deleteOil() – Tom Nov 24 '20 at 10:43
  • 1
    @tom A qualifier is used to identify different objects at the other side (like addressing a hash). The way you use it is wrong. – qwerty_so Nov 24 '20 at 12:43
  • @Tom to elaborate on qwerty_so's comment, suppose `A:worker` works 2 minutes with machine `M1:E1`, and 2 minutes with machine `M2:E1`, and then again with 3 minutes with `M1`. The qualifier here means that A qualified with 2 minutes is associated with two machines. This is not what you mean in you narrative. And it doesn't even take into account if a repair took place between the two events. An association class seems to better express what you'd need. – Christophe Nov 24 '20 at 13:17
  • I am a little bit confused. So if I change the directon of the qualifiers and we just focus on that event if the elapsed_time match the explodeTime (like a bomb), then it calls the workers Die() method. Is it a usable solution with qualifiers? – Tom Nov 24 '20 at 13:46
  • @Tom No problem: we’re here to help. Before answering, could you explain why you chose to use qualifiers, and what you think a qualifier means independently of this specific model (e.g. with two classes A and B and a qualifier q that qualifies A) ? – Christophe Nov 24 '20 at 13:52
  • So in my case when a worker starts to work with the machine (E1) we identify them with the elapsed_time and when it matches with the timeExplode the wroker dies. As I see if we add as an additional requirement that if the workers left the machine (equals to turn off) the counter will be reseted it would be esaier. The reason why I want to use qualifiers instead of class-association, just because I prefer the way to use a single qulaifier instead of a whole class if it is possible. Just I like it better. – Tom Nov 24 '20 at 15:03
  • This is where i read about this: https://stackoverflow.com/questions/64946909/how-to-modelling-different-types-of-fields-and-entities-connection-in-uml?answertab=active#tab-top. Similar problem to mine and also mentioned that it can be done by qulaifier. – Tom Nov 24 '20 at 15:06
  • @Tom Note that in the answer the spontaneous diagram from our expert Bruno uses an association class. I did not understand why a qualifier was mentioned here. I suggest you have a look here: it’s about the purpose of a qualifier: https://www.uml-diagrams.org/property.html#qualifier – Christophe Nov 24 '20 at 16:18
  • @Christophe I added a new class diagram (kept only the main attributes and mehtods) and 2 sequences. Now I use association class. Is this solution better? – Tom Nov 24 '20 at 21:23
  • @Tom ok, it's better, but there is still a lot to be said. I updated my answer to make some more suggestions. But you're now on the good way, so go on ;-) – Christophe Nov 24 '20 at 23:05
  • @Christophe I made some changes so I updated my diagrams. Yes, the Class and Subclass equals to the originals and the duration association class specific to Subclass. – Tom Nov 25 '20 at 11:38
  • @Christophe Could you take a look on my new diagrams? Are they closer to the solution? – Tom Nov 26 '20 at 09:12
  • @Tom ok, in principle this is not a reviewing/coaching site where we keep things open until a perfect solution is found. It’s more a q&a where you get the hints and finalize by yourself. This being said, yes, bothing shocking in the class diagram anymore. First sequence is also ok. Second sequence, there’s still the issue if the opt guard: the check of elapsed tome vs explode time must be done at level of subclass. – Christophe Nov 26 '20 at 16:17