EA&UML日拱一卒-活动图::14.2.3.4 States(状态)(3)

英文原文来自UML2.5,作者提供中文翻译。


14.2.3.4.5 Entering a State(进入状态)


The semantics of entering a State depend on the type of State and the manner in which it is entered. However, in all cases, the entry Behavior of the State is executed (if defined) upon entry, but only after any effect Behavior associated with the incoming Transition is completed. Also, if a doActivity Behavior is defined for the State, this Behavior commences execution immediately after the entry Behavior is executed. It executes concurrently with any subsequent Behaviors associated with entering the State, such as the entry Behaviors of substates entered as part of the same compound transition.

进入状态的语义依赖于状态的类型和进入状态的方式。然而,无 论那种情况,状态的进入行为(如果已经被定义)都会在进入时被执行,但是必须是在与输入迁移相关联的所有效果行为结束之后。同时,如果状态定义了 doActivity行为,该行为在进入行为执行之后立即开始执行。doActivity行为会和与进入状态相关联的所有后续行为并发执行。例如作为同一 次复合迁移一部分的子状态的进入行为。


The above description fully covers the case of simple States. For composite States with a single Region the following alternatives exist:

上面的描述完全覆盖了简单状态的情况。对于单独区域的组合状态来讲,存在下面的变化:


· Default entry: This situation occurs when the composite State is the direct target of a Transition (graphically, this is indicated by an incoming Transition that terminates on the outside edge of the composite State). After executing the entry Behavior and forking a possible doActivity Behavior execution, if an initial Pseudostate is defined, State entry continues from that Vertex via its outgoing Transition (known as the default Transition of the State). If no initial Pseudostate is defined, there is no single approach defined. One alternative is to treat such a model as ill formed. A second alternative is to treat the composite State as a simple State, terminating the traversal on that State despite its internal parts.

默认进入:这种情况发生在组合 状态是迁移的直接目标(从图形角度来看,这意味着一个输入迁移终止于组合状态的外边界)的情况下。在进入行为和可能的doActivity行为分支执行以 后,如果定义了初始伪状态,状态进入动作通过该顶点的输出迁移继续向前。如果没有定义初始伪状态,就意味着没有定义相应的处理。这时要么视该模型为病态, 要么忽略内部的部分,视该组合状态为简单状态而终止遍历。


· Explicit entry: If the incoming Transition or its continuations terminate on a directly contained substate of the composite State, then that substate becomes active and its entry Behavior is executed after the execution of the entry Behavior of the containing composite State. This rule applies recursively if the Transition terminates on an indirect (deeply nested) substate.

明确进入:如果输入迁移或者它的延续终止于组合状态包含的子状态,那么该子状态激活,它的进入行为在包含它的组合状态的进入行为执行之后执行。如果该迁移终止于间接(深度嵌套)子状态,这个规则递归适用。


· Shallow history entry: If the incoming Transition terminates on a shallowHistory Pseudostate of a Region of the composite State, the active substate becomes the substate that was most recently active prior to this entry, unless:

浅历史进入:如果输入迁移终止于组合状态中区域的浅历史伪状态,活动子状态就是之前进入时最近的那个活动子状态。除非:


o the most recently active substate is the FinalState, or

最近的活动子状态是终止状态,或者


o this is the first entry into this State.

第一次进入该状态


o In the latter two cases, if a default shallow history Transition is defined originating from the shallowHistory Pseudostate, it will be taken. Otherwise, default State entry is applied.

在后面的两个场景中,如果定义了开始于浅历史伪节点的默认浅历史迁移,那么这个迁移会发生。否则适用默认进入。


· Deep history entry: The rule for this case is the same as for shallow history except that the target Pseudostate is of type deepHistory and the rule is applied recursively to all levels in the active state configuration below this
one.

深历史进入:除了目的伪状态的类型为深历史伪状态和规则会递归应用得到该状态以下的状态构成的所有层级以外,这种情况下的规则和浅历史进入相同。


· Entry point entry: If a Transition enters a composite State through an entryPoint Pseudostate, then the effect Behavior associated with the outgoing Transition originating from the entry point and penetrating into the State (but after the entry Behavior of the composite State has been executed).

进入点进入:如果迁移通过进入点伪状态进入组合状态,那么与起始于进入点穿入状态的的输出迁移相关联的效果行为将会被执行,但是是在组合状态的进入行为被执行之后。


If the composite State is also an orthogonal State with multiple Regions, each of its Regions is also entered, either by default or explicitly. If the Transition terminates on the edge of the composite State (i.e., without entering the State), then all the Regions are entered using the default entry rule above. If the Transition explicitly enters one or more Regions (in case of a fork), these Regions are entered explicitly and the others by default.

如果组合状态同时还是一个包含多个区域的正交状态,每一个区域都会被进入,可以是默 认的,也可以是明确的。如果迁移终止于组合状态的边界(即没有进入状态),那么所有的区域都适用上面的默认进入规则。如果迁移明确进入了一个或多个区域 (分叉的情况),这些区域为明确进入,其他区域是默认进入。


Regardless of how a State is entered, the StateMachine is deemed to be “in” that State even before any entry Behavior or effect Behavior (if defined) of that State start executing.

无论何种进入方式,状态机都可以视为“处于”某个状态,甚至在该状态进入行为或效果行为(如果被定义)开始执行之前。


14.2.3.4.6 Exiting a State(退出状态)


When exiting a State, regardless of whether it is simple or composite, the final step involved in the exit, after all other Behaviors associated with the exit are completed, is the execution of the exit Behavior of that State. If the State has a
doActivity Behavior that is still executing when the State is exited, that Behavior is aborted before the exit Behavior commences execution.

退出状态时,无论简单状态还是组合状态,在所有和退出状态相关联的行为结束以后,退出的最后一步是执行状态的退出行为。当状态退出时,如果状态的doActivity行为还在执行,那么该行为在退出行为开始执行前被终止。


When exiting from a composite State, exit commences with the innermost State in the active state configuration. This means that exit Behaviors are executed in sequence starting with the innermost active State. If the exit occurs through an exitPoint Pseudostate, then the exit Behavior of the State is executed after the effect Behavior of the Transition terminating on the exit point.

当从组合状态中退出时,退出动作从活动状态构成的最内层状态开始。这意味着退出行为按照从最内层活动状态开始的顺序执行的。如果退出是通过退出点伪状态进行的,那么状态的退出行为是在终止于退出点的迁移的效果行为完了之后执行。


When exiting from an orthogonal State, each of its Regions is exited. After that, the exit Behavior of the State is executed. 

从一个正交状态中退出时,它的每一个区域都退出。然后状态的退出行为被执行。


Regardless of how a State is exited, the StateMachine is deemed to have “left” that State only after the exit Behavior (if defined) of that State has completed execution. 

无论状态是如何退出的,只有在状态的退出行为(如果存在)执行结束之后才可以认为状态机“离开”了该状态。


Encapsulated composite States(封装组合状态)


In some modeling situations, it is useful to encapsulate a composite State, by not allowing Transitions to penetrate directly into the State to terminate on one of its internal Vertices. (One common use case for this is when the internals of a State in an abstract Classifier are intended to be specified differently  in different subtype refinements of the abstract Classifier.) Despite the encapsulation, it is often necessary to bind the internal elements of the composite State with incoming and outgoing Transitions. This is done by means of entry and exit points, which are realized via the entryPoint and exitPoint Pseudostates.

在某些场景中,封装一个组合状态是有用的。方法是禁止迁移直接穿入状态并终止于该状态的内部顶点。(一 个常见的情况是当状态的内部是一个打算通过定义不同的子类型来深化的抽象类目),尽管被封装了,还是经常需要将组合状态的内部元素和进入/离开迁移绑定, 其方法是利用进入和退出点。进入和退出点是由entryPoint和exitPoint伪状态实现的。


Entry points represent termination points (sources) for incoming Transitions and origination points (targets) for Transitions that terminate on some internal Vertex of the composite State. In effect, the latter is a continuation of the
external incoming Transition, with the proviso that the execution of the entry Behavior of the composite State (if defined) occurs between the effect Behavior of the incoming Transition and the effect Behavior of the outgoing
Transition. If there is no outgoing Transition inside the composite State, then the incoming Transition simply performs a default State entry.

进入点表达了输入迁移的终止点和终 止于组合状态的内部顶点的迁移的起始点。实际上,接下来是外部输入迁移的延续,这里有一个附加条件:那个组合状态的进入行为(如果存在)的执行发生在进入 迁移的效果行为和离开迁移的效果行为之间。如果组合状态内部没有离开迁移,那么进入迁移只是简单地执行默认的状态进入。


Exit points are the inverse of entry points. That is, Transitions originating from a Vertex within the composite State can terminate on the exit point. In a well-formed model, such a Transition should have a corresponding external Transition outgoing from the same exit point, representing a continuation of the terminating Transition. If the composite State has an exit Behavior defined, it is executed after any effect Behavior of the incoming inside Transition and before any effect Behavior of the outgoing external Transition.

退出点是进入点的反转。也就是说,开始于组 合状态内部的某顶点上的迁移可以终止于退出点。在定义良好的模型中,这样的迁移应该拥有一个与之对应的外部迁移离开同一个退出点,用以表达终止迁移的延 续。如果组合状态定义了退出行为,这个行为在内部进入迁移的效果行为之后,外部离开迁移的效果行为之前被执行。


14.2.3.4.7 Submachine States and submachines(子状态机状态和子状态机)


Submachines are a means by which a single StateMachine specification can be reused multiple times. They are similar to encapsulated composite States in that they need to bind incoming and outgoing Transitions to their internal Vertices. However, whereas encapsulated composite States and their internals are contained within the StateMachine in which they are defined, submachines are, like programming language macros, distinct Behavior specifications, which may be defined in a different context than the one where they are used (invoked). Consequently, they require a more complex binding. This is achieved through the concept of submachine State (i.e., States with isSubmachineState = true), which represent references to corresponding submachine StateMachines. The concept of ConnectionPointReference is provided to support binding between the submachine State and the referenced StateMachine. A ConnectionPointReference represents a point on the submachine State at which a Transition either terminates or originates. That is, they serve as targets for incoming Transitions to submachine States, as well as sources for outgoing Transitions from submachine States. Each ConnectionPointReference is matched by a corresponding entry or exit point in the referenced submachine StateMachine. This provides the necessary binding mechanism between the submachine invocation and its specification.

子状态机是一个状态机定义可以被多次复用的方式。它也需要将进入和离开迁移绑定到内部顶点上,这一点与封装组 合状态类似。封装组合的场合,状态和它的内容被定义它们的状态机所包含,子状态机更像编程语言中的宏,而不是行为定义。定义和使用(调用)它们地方可以有 不同的上下文。因此它们需要更复杂的绑定过程。这是通过子状态机状态(即isSubmachineState属性为真)的概念实现的,它表现的是对对应子 状态机的参照。提供连接点参照是为了支持子状态机状态和它所参照的状态机之间的绑定。连接点参照表现为子状态机状态中一个点,迁移在这个点开始或结束。也 就是说,连接点参照既可以作子状态机状态进入迁移的目标,也可以作子状态机状态离开迁移的源。每个连接点参照都和被参照子状态机中的进入点和退出点相对 应。通过这种方式提供了子状态机调用和定义之间绑定的机制。


A submachine State implies a macro-like insertion of the specification of the corresponding submachine StateMachine. It is, therefore, semantically equivalent to a composite State. The Regions of the submachine StateMachine are the Regions of the composite State. The entry, exit, and effect Behaviors and internal Transitions are defined as contained in the submachine State.

子状态机状态实现了一个类似于宏的定义插入子状态机的方法。因此,语义上等价于组合状态。


NOTE. Each submachine State represents a distinct instantiation of a submachine, even when two or more submachine States reference the same submachine.

注意:每一个子状态状态代表了子状态机的一个不同的实例,即使是两个或多个状态机状态参照同一个子状态机时也是如此。


A submachine StateMachine can be entered via its default (initial) Pseudostate or via any of its entry points (i.e., it may imply entering a non-orthogonal or an orthogonal composite State with Regions). Entering via the initial Pseudostate has the same meaning as for ordinary composite States. An entry point is equivalent to a junction Pseudostate (fork in cases where the composite State is orthogonal): Entering via an entry point implies that the entry Behavior of the composite state is executed, followed by the Transition from the entry point to the target Vertex within the composite State. Any guards associated with these entry point Transitions must evaluate to true in order for the specification to be well formed.

子状态机的进入可以通过它的默认(初始)伪状态,或者是任意的进入点 (即,可以实现进入一个包含区域的非正交或正交组合状态)。通过起始伪状态进入和通常组合状态具有相同的含义。进入点等价于连接点伪状态(正交组合状态的 场合相当于分叉):通过进入点的进入的实现:组合状态的进入行为被执行,接下来是从进入点到组合状态内部的目标顶点的迁移。所有与这些进入点迁移关联的保 护条件都必须演算结果为真以保证模型是被良好定义的。


Similarly, a submachine Statemachine can be exited as a result of:

类似的,子状态机可以在以下情况时退出:

· reaching its FinalState,

到达终止状态,
· triggering of a group Transition originating from a submachine State, or

源自子状态机的一组迁移被触发。

· via any of its exit points.

通过退出点。


Exiting via a FinalState or by a group Transition has the same meaning as for ordinary composite States.

通过终止状态退出或者通过一组迁移退出具有相同的含义,这一点和通常的组合状态一样。


参考资料:

《OMG Unified Modeling Language TM (OMG UML) Version 2.5》

  URL:http://www.omg.org/spec/UML/2.5\


阅读更多更新文章,请扫描下面二维码,关注微信公众号【面向对象思考】


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值