UML状态图中保护和事件之间的区别 [英] Difference between guard and event in UML state diagram

查看:229
本文介绍了UML状态图中保护和事件之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我可以区分事件后卫。但是我遇到了一个类似于后卫的事件:

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

在其中,我将变量计数器从小于4的某个值更改为大于4的事件。

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?

推荐答案

一个事件就是那个东西吗?触发过渡。在您的情况下计数器> 4 是更改事件,表示 计数器值已更改,并且其值现在大于4

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.

在C中,它看起来可能像这样:

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();
} 

根据UML 2.5规范:


14.2.3.8转换
...
转换可能拥有一组触发器,每个事件都指定一个事件
,该事件在分派时可能会触发遍历
过渡。如果已调度的
事件发生与其事件类型匹配,则启用了过渡触发器。

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过渡 .. 。
过渡的默认文本符号由
定义,并带有以下BNF表达式:

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

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


换句话说:触发[后卫] /行为

这篇关于UML状态图中保护和事件之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆