复合状态和内部转换

Composite state and internal transitions

前提是我现在在StateB。 Sig2 来了。因此不会执行进入或退出,而只会执行 Act5。到目前为止一切顺利。

现在我们在StateC,但是这次Sig1 来了。定义了一个内部转换,但处于父复合状态。我是否必须退出 StateC,执行 Act2 并转到初始连接器并进入 StateB?

我没有在 UML 标准中找到这个问题的答案。

您不需要退出 StateC,只要您处于其某些子状态中,拥有状态的内部转换总是会发生。

14.5.12.3 Literals

  • internal
    • Implies that the Transition, if triggered, occurs without exiting or entering the source State (i.e., it does not cause a state change). This means that the entry or exit condition of the source State will not be invoked. An internal Transition can be taken even if the SateMachine is in one or more Regions nested within the associated State.

这是有道理的——您总是处于复合状态的某个子状态。 (一旦进入复合状态,它会立即(在 entry 行为之后)进入第一个状态)。

当然,内部转换不会更改状态配置,因此它会保持不变 (<StateA::StateC>)。

当然,这一切都是假设您传送到 StateC,因为那个状态是无法到达的。

The Wikipedia article on UML statecharts 目前做出一个明确的断言来解决这个问题:

In contrast to a self-transition, no entry or exit actions are ever executed as a result of an internal transition, even if the internal transition is inherited from a higher level of the hierarchy than the currently active state. Internal transitions inherited from superstates at any level of nesting act as if they were defined directly in the currently active state.

很遗憾,它没有来源。我同意 @user2281723 的说法,该规范不明确。来自 UML 2.5 的第 14.2.3.8.1 节:

internal is a special case of a local Transition that is a self-transition (i.e., with the same source and target States), such that the State is never exited (and, thus, not re-entered), ..

如果这意味着整个活动状态配置(嵌套层次结构中的所有活动状态)未退出,则没有状态更改。如果这意味着只有拥有内部转换的特定状态没有退出,那是否意味着所有子状态都将退出并且具有转换的状态将成为活动状态?那是模型中转换的目标状态。

我怀疑第一个含义是规范编写者的意图,也是实践中使用的含义。希望最终能在规范中添加说明。