UML 状态图和 Moore/Mealy 机器

UML state diagrams and Moore/Mealy machines

如何使用 UML 状态图对 Moore 和 Mealy 机器建模?此外,如何在这些图中表示输出?通过行动?

状态机可以定义行为(最新 UML 2.5.1 规范的第 309 页):

14.2.3.4.3 State entry, exit, and doActivity Behaviors

A State may have an associated entry Behavior. This Behavior, if defined, is executed whenever the State is entered through an external Transition. In addition, a State may also have an associated exit Behavior, which, if defined, is executed whenever the State is exited.

A State may also have an associated doActivity Behavior. This Behavior commences execution when the State is entered (but only after the State entry Behavior has completed) and executes concurrently with any other Behaviors that may be associated with the State, until:

  • it completes (in which case a completion event is generated) or
  • the State is exited, in which case execution of the doActivity Behavior is aborted.

The execution of a doActivity Behavior of a State is not affected by the firing of an internal Transition of that State.

继续阅读第 1 页。 320关于后者的符号。

UML 状态图具有 Mealy 和 Moore 状态机的特点。

要表示一个纯 Mealy 机,您只对转换使用操作:

stateA -- TRIGGER [guard] / action() --> stateB

要表示纯摩尔机,您仅使用状态的进入或退出动作,但不使用转换动作:

stateA
   entry/ actionA();

stateB
   entry/ actionB();

当您同时使用转换动作和 entry/exit 状态动作时,您会混合使用 Mealy 和 Moore 机器。