UML状态图中,guard和event之间的区别是什么?

3

我曾以为我可以区分事件守卫。但我发现一个事件与守卫类似:

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

我观察到变量计数器从小于4的某个值改变为大于4的某个值,这被视为一个事件。那是否意味着事件也可以像守卫条件一样成为一个条件?

1个回答

2
一个事件是触发状态转换的事情。在您的情况下,counter > 4是一个变化事件,意思是“计数器值已经改变,并且它的值现在大于4”。
括号中的代码是保护条件。在您的情况下,pin is high表示“只有当引脚高电平时才能执行转换”。 switch on是执行转换时执行的行为
注:在您的示例中,事件确实非常类似于保护条件。
在C语言中,代码可能如下所示:
/** 
 * this interrupt is triggered when the
 * counter exceeds the threshold (4)
 */
static void counter_isr(void)
{
   if (pin_is_high(PIN))
       switch_on();
} 

来自 UML 2.5 规范:

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>]]
换句话说:触发器 [守卫条件] / 行为

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接