Difference between guard and event in UML state diagram

我只是一个虾纸丫 提交于 2020-01-02 08:53:10

问题


I thought I could differentiate between event and guard. But I came across an event being similar to guard:

counter > 4 [pin is high] / switch on
^^^^^^^^^^^ 
   event

where I viewed the variable counter changes from some value smaller than 4 to that greater than 4 as event. Does that mean event can also be a condition like guard?


回答1:


An event is the thing that triggers the transition. In your case counter > 4 is a change event, meaning "the counter value has changed and its value is now greater than 4".

The code between the brackets is the guard. In your case pin is high, meaning "the transition is only enabled if the pin is high".

switch on is the behavior that is executed when the transition is executed.

Footnote: In your example the event is indeed very similar to the guard.

In C it could look like that:

/** 
 * this interrupt is triggered when the
 * counter exceeds the threshold (4)
 */
static void counter_isr(void)
{
   if (pin_is_high(PIN))
       switch_on();
} 

From the UML 2.5 specification:

14.2.3.8 Transitions ... A Transition may own a set of Triggers, each of which specifies an Event whose occurrence, when dispatched, may trigger traversal of the Transition. A Transition trigger is said to be enabled if the dispatched Event occurrence matches its Event type.

14.2.4.9 Transition ... The default textual notation for a Transition is defined by the following BNF expression:

[<trigger> [‘,’ <trigger>]* [‘[‘ <guard>’]’] [‘/’ <behavior-expression>]]

In other words: trigger [guard] / behavior



来源:https://stackoverflow.com/questions/32403869/difference-between-guard-and-event-in-uml-state-diagram

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!