(翻譯)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
以上就是今天的文章,歡迎點贊並推薦給您的朋友!
閱讀更多更新文章,請關注【面向對象思考】微信公眾號!
推薦閱讀:
※EA&UML日拱一卒--序列圖(Sequence Diagram)::時間約束
※大話設計模式之簡單工廠模式與策略模式
※實用OOPC
※Python實用技巧——類,屬性與裝飾器