如何解释 UML 2.5 状态机图?

How to interpret a UML 2.5 State Machine diagram?

我需要识别 UML 2.5 状态机图的所有基本元素。不幸的是,这些图表的符号似乎有很多歧义,因为网上有很多不同的变体。

我的解释是,每个状态机图都由多个状态和多个转换组成。

每个州都有:

每个转换都有:

我对符号工作原理的理解可以在图 1 中进行总结(遵循符号 [precondition] Event / [Transition Action][=90 的电动门功能示例=]) 和图 2.

示例: 当触发 事件 时(例如按下关闭按钮),评估 precondition(如果有)(例如门口是否空着)并且如果 precondition满足,触发转换动作(如关门)

图一

图2

我的问题:

  1. Transition Actiontransition的实现还是 只是在过渡期间发生的一个动作。简单来说, 如果转换action/s出错,转换(新 状态)会成功吗?我的问题基本上源于事实 许多消息来源建议不要使用 transition action,到达新的时候可以使用一个入口action 状态。据我了解,虽然 过渡动作 是 过渡的实现,因此发生在进入之前 新状态,与发生的 进入操作 相比 到达新状态后立即。因此,就转换本身和时间而言,这是两种完全不同类型的操作。了解这些操作的时机对我来说至关重要。
  2. 我的一般解释是否正确? (例如我对什么是事件的理解,post-condition 和 transition-action 可能来自图 1)

我知道状态机图有多种变体,因此有不同的表示/解释,但我对 UML 2.5 感兴趣。

转换动作是 UML 2.5 声明的转换的关联结束:

effect : Behavior [0..1]{subsets Element::ownedElement} (opposite A_effect_transition::transition) Specifies an optional behavior to be performed when the Transition fires.

而状态的 <<entry>> 是分配给状态本身的行为。也就是说,它将从转换来自的地方触发。相比之下,上面的effect只在过渡时触发。

效果不行"go wrong"。无论执行什么行为,都会执行。这里没有检查条件。

是否触发转换可以通过您错误命名为[precondition][guard]来控制。 (可以开始争论了,但你需要[guard]。)

guard : Constraint [0..1]{subsets Namespace::ownedRule} (opposite A_guard_transition::transition) A guard is a Constraint that provides a fine-grained control over the firing of the Transition. The guard is evaluated when an Event occurrence is dispatched by the StateMachine. If the guard is true at that time, the Transition may be enabled, otherwise, it is disabled. Guards should be pure expressions without side effects. Guard expressions with side effects are ill formed.

关于时间,您可以想到在各州旅行的代币。当守卫让你通过时,就会执行 <<exit>> 行为。然后是转换的 effect,最后是下一个状态的 <<entry>> 行为。