Difference between event and guard uml modeling

3.5k views Asked by At

I don't really see the difference between a guard and an event in state diagram , what I can see is that an event is an action that has been launched or something like that and a guard is a just a condition but I think it's more profound than that I don't know if these two terms are associated or separated, which one is necessary and which one is optional or the difference exists just between their syntaxes; an event is written without brackets, it would be great if you could help me with this.

Thanks in advance. [ Sorry if I misspelled something ]

2

There are 2 answers

1
sfinnie On BEST ANSWER

An event is an action that has been launched or something

Close. An event is simply something that has happened. Like a train arriving at the station, a light switch being turned on, or (in line with the season) Santa popping down the chimney.

a guard is just a condition

Exactly. So for a state transition to fire, the event must occur AND the guard must evaluate to true. So the transition into state "leaving presents" requires both Santa to arrive (event) AND the chimney be unblocked (guard).

Which one is necessary and which is optional

Essentially every transition requires an event. It does not require a guard. So the light can transition into the 'illuminated" state when the switch is turned on. No need for a guard.

An event is written without brackets

Yes. The event has no brackets, the guard ( if there is one) is placed in square brackets. So

Santa Arrives [chimney unblocked]

Hth.

0
BobRodes On

In a state diagram, the event is what causes a transition between states. As a simple example, a Door has two states, Open and Closed. ReadIDCard is the event that transitions the current state from Closed to Open.

A guard condition determines whether the receiving object should respond to the event. For example, the ['AuthorizedID'] guard will check to see if the Card ID is authorized before changing the state to Open. If there is no guard condition, ReadIDCard will always open the door.

To illustrate a bit further, when the state of the Door changes to Open, a Timer event (after waiting for, say, five seconds) changes the state of the Door to Closed again. In this case, there is no guard condition; anyone standing in the doorway gets squashed. :)

So, the terms are different. There is always some sort of event that causes transition from one state to another. Guard conditions are optional. From the standpoint of a diagram, whether you add events and guard conditions is optional.