(翻譯)14.4 ProtocolStateMachines

英文原文來自UML2.5,作者提供中文翻譯。

14.4.1 Summary(概要)

ProtocolStateMachines are used to express usage protocols. ProtocolStateMachines express the legal sequences of Event occurrences to which the Behaviors of an associated BehavioredClassifier must conform. The StateMachine notation is a convenient way to define the order of invocations of the behavioral features of a Classifier.

協議狀態機用於表現使用方法的協議。協議狀態機表示事件發生的合法的序列,關聯的行為類目的行為必須遵循這個序列。狀態機記法是一種定義類目的行為特徵的調用次序的簡便方式。

ProtocolStateMachines can be associated with Classifiers, Interfaces, and Ports.

協議狀態機可以和類目,介面和埠關聯。

14.4.2 Abstract Syntax

Figure 14.41 ProtocolStateMachines

14.4.3 Semantics(語義)

14.4.3.1 ProtocolStateMachine(協議狀態機)

A ProtocolStateMachine is always defined in the context of a Classifier. It specifies which BehavioralFeatures of that Classifier can be invoked in a given protocol state and under what conditions, thereby specifying allowed invocation sequences. In this manner, a specification of the lifecycle of an instance of the Classifier is defined from an external perspective.

協議狀態機總是在類目的上下文中定義。它定義了類目的在一個給定的協議狀態中,什麼條件下,哪個行為特徵可以被調用。這樣,從外部觀點定義了類目的某個實例的生命周期的規範。

ProtocolStateMachines help define the order in which BehavioralFeatures of a Classifier are invoked by specifying:

協議狀態機幫助定義類目的行為特徵被調用的順序,它明確了:

? the behavioral context (i.e., which states and pre-conditions) in which they can be validly invoked,

它們可以被正確調用時的行為上下文(即:哪個狀態和前置條件)

? the valid orderings of invocations,

正確的調用次序,

? the expected outcomes (post-conditions) of invocations.

期待的調用輸出(後置條件)

ProtocolStateMachine present an external view of the owning Classifier as perceived by its collaborators. This extends beyond what can be captured via pre- and post-conditions on individual BehavioralFeatures, as ProtocolStateMachines also specify the valid orderings of invocations of the different features. This is achieved by a state machine specification in which the transition triggers are feature invocations and the guards of the transitions (ProtocolTransitions) specify the pre-condition that must apply for the invocation to be valid. The states (ProtocolStates) of this state machine, being a consequence of past invocation sequences, capture the state of the protocol and are also a form of pre-condition.

協議狀態機向協作者呈現了一個包含協議狀態機的類目的外部視圖。這種擴展依據的是通過獨立的 行為特徵的前置條件和後置條件可以捕捉到什麼,協議狀態機也可以定義不同特徵的正確的調用次序。這是通過狀態機定義實現的,在這個定義中,為了保證調用的 正確性,功能調用的觸發條件和遷移的定義後置條件的監護條件必須使用以保證調用的正確性。作為過去的調用序列的結果,狀態機的狀態(協議狀態)捕捉協議的 狀態並且也是前置條件的一種形式。

NOTE. Because ProtocolStateMachines provide a 「black box」 view of the behavior of a Classifier, their States may not necessarily correspond to the States of internal behavioral StateMachines.

因為協議狀態機提供的是類目行為的「黑盒」視圖,狀態不必和內部行為狀態機的狀態相對應。

ProtocolStateMachine interpretation can vary from:

協議狀態機可以有不同的形式:

1 Declarative ProtocolStateMachines, which specify the legal Transitions for BehavioralFeature invocations.The effects of a BehavioralFeature invocation is not specified. This type of specification only provides a contract for the user of the context Classifier.

陳述性協議狀態機,它定義了行為特徵調用的有效遷移。不定義行為特徵調用的效應。這種類型的定義只是向上下文類目的用戶提供一種約定。

2 Executable (run time) ProtocolStateMachines, which specify all Event occurrences that an object may receive and handle, together with the Transitions that these trigger. In this case, the legal Transitions for BehavioralFeature invocations must match exactly the triggered Transitions or a run-time exception occurs.The invocation results in the execution of the method associated with the invoked BehavioralFeatures.

可執行(執行時)協議狀態機,它定義了一個對象可以接受和處理的所有事件發生和它們觸發的遷移。在這種情況下,正當的行為特徵調用遷移必須和被觸發的遷移或運行時例外完全匹配。方法執行的調用結果和被調用的行為特徵相關聯。

The specifications for both interpretations is the same, the only difference being the direct dynamic implication that the latter interpretation provides.

兩種解釋的定義都相同,唯一的區別就是後一種解釋提供了直接的動態含義。

The more sophisticated forms of modeling encountered in behavioral StateMachines such as compound Transitions, submachine StateMachines, composite States, and concurrent orthogonal Regions, can also be used for ProtocolStateMachines. For example, concurrent Regions make it possible to express protocols where an instance can have several active States simultaneously. Submachine StateMachines and compound transitions can be used for factorizing complex ProtocolStateMachines.

在行為狀態機中遇到的更加複雜的形式,例如複合遷移,子狀態機,組合狀態,並發正交區域等,也可以用於協議狀態機。例如並發區域可以用於表現一個實例同時擁有多個活動狀態的情況。子狀態機和複合遷移可以用於分解複雜的協議狀態機。

A Classifier may have several ProtocolStateMachines. This can be used, for example, when a Classifier has multiple parents, each having its own ProtocolStateMachine, and the protocols are orthogonal. An alternative to this is to simply have one ProtocolStateMachine, with distinct StateMachines in concurrent Regions.

一個類目可以有多個協議狀態機。例如下面的場景:一個類目擁有多個父母(類目),每個擁有自己的協議狀態機,且協議之間為正交關係。另一種方式是只擁有一個協議狀態機,但是在它的並發區域中包含不同的狀態機。

State in ProtocolStateMachines(協議狀態機中的狀態)

The States of ProtocolStateMachines are exposed to the users of their context Classifiers. A protocol State represents an exposed stable situation of its context Classifier: When an instance of the Classifier classifier is not processing any BehavioralFeature invocation, users of this instance can always know its state configuration.

協議狀態機的狀態被暴露給它們的上下文類目的用戶。一個協議狀態表現了它的上下文類目的一個外部可見的穩定情況:當類目的某個實例沒有處理任何的行為特徵調用時,那個實例的用戶總是知道它的狀態構成。

The States of a ProtocolStateMachine cannot have defined entry, exit, or doActivity Behaviors.

協議狀態機的狀態不允許定義進入,退出和doActivity行為。

14.4.3.2 ProtocolTransition(協議遷移)

A ProtocolTransition specifies a legal Transition for an invocation of a BehavioralFeature of the context Classifier. ProtocolTransitions have the following features:

協議遷移定義了上下文類目的行為特徵在被調用時允許的遷移。協議遷移有如下特徵:

· a pre-condition (preCondition), which specializes the guard attribute of Transition,

定義遷移的監護屬性的前置條件,

· a trigger,

觸發條件,

· a post-condition (postCondition).

後置條件。

The protocol Transition specifies that (a) the associated (referred) feature can be invoked on an instance of the context Classifier, if it is in the origin State and the guard condition holds, and that (b) upon completion of the Transition, the instance will be in the target State in which the post-condition will hold.

協議遷移定義了上下文類目的實例可以被調用的關聯(引用)特徵,如果它位於初始狀態內,有監護條件,被遷移完成觸發,那麼這個實例將會處於擁有後置條件的目標狀態中。

ProtocolTransitions do not have an associated effect Behavior. The consequence of a ProtocolTransition executed as a result of a BehavioralFeature invocation is implicit: it is the execution of the method corresponding to the invoked BehavioralFeature. In case of other types of Triggers, the consequences are unspecified except that a Transition will lead to another State under a specific post-condition, regardless of any Behaviors associated with this Transition.

協議遷移沒有關聯的效應行為。作為行為特徵調用的結果,協議遷移的意味著與被調用行為特徵相關聯的方法的執行。在其他類型觸發條件的情況下,影響是沒有定義的,除非該遷移會引出另外一個滿足特定前置條件的狀態,這時不考慮與這個遷移相關聯的任何行為。

14.4.3.2.1 Unexpected trigger reception(非預期觸發接受)

The interpretation of the reception of an Event occurrence that does not match a valid trigger for the current State, state invariant, or pre-condition is not defined (e.g., it can be ignored, rejected, or deferred; an exception can be raised; or the application can stop on an error). It corresponds semantically to a pre-condition violation, for which no predefined Behavior is defined in UML.

關於沒有和當前狀態,狀態不變數或前置條件匹配的事件發生的接受的解釋沒有被定義(即,它可以被忽略,拒絕或推遲;升起異常;或作為錯誤而終止應用的執行)。在語義上它對應於前置條件的違反,在UML中沒有為它設定預先定義的行為。

14.4.3.2.2 Unexpected Behavior(非預期行為)

The interpretation of an unexpected Behavior, that is an unexpected result of a Transition (wrong FinalState or FinalState invariant, or post-condition) is also not defined. However, this should be interpreted as an error of the implementation of the ProtocolStateMachine.

作為遷移的非預期結果(錯誤的完了狀態,或完了狀態不變數,或後置條件),非預期行為的解釋也無定義。然而它應該被解釋成協議狀態機實現的錯誤。

14.4.3.2.3 Equivalences to pre- and post-conditions of operations(操作的前置和後置條件的等價性)

A protocol Transition can be semantically interpreted in terms of pre- and post-conditions on the associated operation.For example, the Transition in

Figure 14.42 can be interpreted in the following way:

在語義上,協議遷移可以從操作的前置和後置條件兩個方面來解釋。例如圖14.42中的遷移可以按以下方式解釋:

1 The operation 「m1」 can be called on an instance when it is in the ProtocolState 「S1」 under the condition 「C1.」

當實例處於協議狀態"S1",滿足條件「C1」時,操作m1可以被調用。

2 When 「m1」 is called in the ProtocolState 「S1」 under the condition 「C1,」 then the ProtocolState 「S2」 must be reached under the condition 「C2.」

當處於協議狀態「S1」s時,「m1」被調用,那麼滿足條件」C2「時,必須到達協議狀態"S2「。

Figure 14.42 An example of a ProtocolTransition associated with the operation "m1"

Operations referred by several Transitions(被多個遷移引用的操作)

Figure 14.43 Example of several ProtocolTransitions associated with the same operation (m1)

In a ProtocolStateMachine, several Transitions can refer to the same operation as illustrated in Figure 14.43. In that case, all pre-and post-conditions will be combined in the operation pre-condition as shown below.

圖14.43表示了在協議狀態機中,多個遷移可以引用同一個操作的例子。在這個情況下,所有的前置和後置條件都被組入操作的前置(/後置)條件,表示如下

Operation m1()

Pre: in state S1 and condition C1

or

in state S3 and condition C3

Post: if the initial condition was 「in state S1 and condition C1」

then in S2 and C2

else

if the initial condition was 「in state S3 and condition C3」

then in S4 and C4

A ProtocolStateMachine specifies all the legal ProtocolTransition for each BehavioralFeature referred by its Transitions.

協議狀態機為它的遷移所引用的每個行為特徵定義了所有的協議遷移。

Unreferred Operations(沒有被引用的操作)

If a BehavioralFeature is not referred by any ProtocolTransition, then the operation can be called for any State of the ProtocolStateMachine, and will not change the current State or pre- and post-conditions.

如果行為特徵沒有被任何的行為特徵引用,那麼該操作可以被協議狀態機的任何狀態調用,並且不會改變當前狀態或前置/後置條件。

14.4.3.2.4 Using other types of Events in ProtocolStateMachines(在協議狀態機中使用其他類型的事件)

Apart from invocations of BehavioralFeatures, other Events may be used for expressing the behavior of ProtocolStateMachines. A Trigger that is not a BehavioralFeature invocation can be specified for a protocol Transition. In that case, this specification is a requirement for the environment external to the ProtocolStateMachine. That is, it is legal to send an Event occurrence of this type to an instance of the context Classifier only under the conditions specified by the ProtocolStateMachine. The precise semantic interpretation of this is not defined.

除了調用行為特徵,可以使用另外的事件來表現協議狀態機的行為。不是行為特徵調用的觸發條件可以用於定義協議遷移。這種 定義是對於行為狀態機外部環境的需求。也就是說,只有滿足協議狀態機定義的條件時,向上下文類目發送事件發生才是合乎要求的。與此有關的準確的語義解釋沒 有被定義。

14.4.3.3 ProtocolConformance(協議一致)

ProtocolStateMachines can be refined into more specific ProtocolStateMachines. Protocol conformance declares that the specific ProtocolStateMachine specifies a protocol that conforms to that specified by the general ProtocolStateMachine.

協議狀態機可以被定義為更加具體的協議狀態機。協議一致聲明了具體的協議狀態機定義了一個協議,它與泛用協議狀態機定義的協議一致。

A ProtocolStateMachine is owned by a Classifier. The Classifiers owning a general StateMachine and an associated specific StateMachine are generally also connected by a Generalization or a Realization.

協議狀態機屬於類目。該類目擁有一個泛用狀態機,而且通常情況下,也會通過泛化和實現關聯一個具體的狀態機。

Protocol conformance represents a declaration that every rule and constraint specified for the general ProtocolStateMachine (state invariants, pre- and post-conditions for the operations referred by the ProtocolStateMachine) apply to the specific ProtocolStateMachine.

協議一致表示一個聲明:為泛用協議狀態機定義的所有規則,約束(狀態不變數,協議狀態機引用的操作的前置/後置條件)都會適用與具體的協議狀態機。

14.4.4 Notation(記法)

14.4.4.1 ProtocolStateMachine(協議狀態機)

The notation for ProtocolStateMachine is very similar to the one for behavioral StateMachines. The keyword ?protocol? placed close to the name of the StateMachine differentiates graphically ProtocolStateMachine diagrams.

協議狀態機的記法和行為狀態機非常相似。只是通過靠近狀態機名稱的?protocol?關鍵詞從圖形上區別了協議狀態機圖。

Figure 14.44 ProtocolStateMachine example

The textual expression of an invariant associated with a State in a ProtocolStateMachine is represented by placing it after or under the name of the State, enclosed in square brackets (Figure 14.45).

與協議狀態機中的狀態相關聯的不變數的文字表達式的表示方法,是通過將其封裝入括弧中,放到狀態名之後或之下。

Figure 14.45 Notation for a State with an invariant

14.4.4.2 ProtocolTransition(協議遷移)

The usual StateMachine notation applies. The difference is that no effect Behaviors are specified for ProtocolTransitions, and that post-conditions can exist. Post-conditions have the same syntax as guard conditions, but appear at the end of the Transition syntax.

使用通常的狀態機中的記法。區別是不會定義效應行為和可以有後置條件。後置條件和監護條件的語法相同,但是遷移語法的最後表示。

Figure 14.46 ProtocolTransition notation

以上就是今天的文章,歡迎點贊並推薦給您的朋友!

閱讀更多更新文章,請關注【面向對象思考】微信公眾號!

參考資料:

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

URL:About the Unified Modeling Language Specification Version 2.5


推薦閱讀:

在軟體開發過程中,有哪些UML圖是比較常用的?
UML詳細講到底是一個怎樣的概念?
你認為最好的 UML 建模工具是哪一個(最好是免費軟體)?
如何畫UML的時序圖?
業務實時監控的統一抽象

TAG:面向對象編程 | 面向對象分析與設計 | UML建模 |