1

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 ]

4

2 回答 2

4

事件是已经启动的动作什么的

关。事件只是已经发生的事情。就像火车到达车站,打开电灯开关,或者(根据季节)圣诞老人从烟囱里冒出来。

守卫只是一个条件

确切地。因此,对于触发状态转换,事件必须发生并且守卫必须评估为真。因此,转换到“离开礼物”状态需要圣诞老人到达(事件)和烟囱畅通(守卫)。

哪个是必要的,哪个是可选的

基本上每个过渡都需要一个事件。它不需要守卫。因此,当开关打开时,灯可以过渡到“照明”状态。无需防护。

事件不带括号

是的。事件没有括号,守卫(如果有的话)放在方括号中。所以

Santa Arrives [chimney unblocked]

嗯。

于 2014-12-18T22:36:29.173 回答
2

在状态图中,事件是导致状态之间转换的原因。举个简单的例子,门有两种状态,打开和关闭。ReadIDCard 是将当前状态从 Closed 转换为 Open 的事件。

警戒条件确定接收对象是否应响应事件。例如,['AuthorizedID'] 守卫将在将状态更改为 Open 之前检查卡 ID 是否已授权。如果没有守卫条件,ReadIDCard 会一直开门。

为了进一步说明,当门的状态更改为打开时,计时器事件(例如,在等待五秒后)将门的状态再次更改为关闭。在这种情况下,没有警戒条件;站在门口的人都会被压扁。:)

所以,条款不同。总会有某种事件导致从一种状态转换到另一种状态。保护条件是可选的。从图表的角度来看,是否添加事件和保护条件是可选的。

于 2014-12-19T15:35:29.590 回答