天天看點

EA&UML日拱一卒-活動圖::14.3 StateMachine Redefinition

14.3.1 Summary(概要)

StateMachines are used for the definition of Behavior (for example, Classes that are generalizable). As part of the specialization of a Class it may be required to specialize its Behavior definitions. This is achieved by defining the

Behavior of the specialized Classifier as an extension of the Behavior of the general Classifier using redefinition.

狀态機用于定義行為(例如可以泛化的類)。作為類特化的一部分,有時會需要對它的行為定義進行特化。實作的方式就是通過重定義來定義特化類目的行為,把它作為泛用類目行為的擴充。

14.3.2 Abstract Syntax(抽象文法)

EA&UML日拱一卒-活動圖::14.3 StateMachine Redefinition

Figure 14.37 StateMachine redefinition

14.3.3 Semantics(語義)

14.3.3.1 StateMachine Extension(擴充狀态機)

A StateMachine is generalizable. A specialized StateMachine is an extension of the general StateMachine, such that  

狀态機是可以泛化的。特化的狀态機是泛用狀态機的擴充,例如

· new Regions, Vertices, and Transitions may be added; 

 增加新的區域,頂點和遷移;

· Regions and States may be redefined (e.g., simple States can be redefined as composite States while composite States can be redefined by adding States and Transitions); and

重新定義區域和狀态(例如,簡單狀态可以重新定義為組合狀态,而組合狀态可以增加狀态和遷移);而且

· Transitions can be redefined.

重新定義遷移

This can be done as part of Classifier specialization; that is, StateMachine behaviors and classifierBehaviors owned by a general Classifier can be specialized as can StateMachines that specify the methods of Behavioral features of a general Classifier.

上述行為可以作為類目特化的一部分;也就是說,泛用類目擁有的狀态機行為和狀态機類目行為可以像通常類目的行為特征的方法的狀态機一樣被特化。

A specialized StateMachine will have all the elements of the general StateMachine, and it may include additional elements. Regions may be added. Inherited Regions may be redefined by extension: States and Vertices are inherited,

and States and Transitions of the Regions of the StateMachine may be redefined.

被特化的狀态機将會擁有泛用類的所有元素,并且會引入追加的元素。區域可以被追加。內建的區域可以通過擴充被重新定義:狀态和頂點被繼承,狀态機區域中的狀态和遷移可以被重新定義。

14.3.3.1.1 State redefinition(重新定義狀态)

A simple State may be redefined (extended) to become a composite State by one or more Regions. A composite State can be redefined (extended) by:

簡單狀态可以通過增加一個或多個區域變成組合狀态的方式進行重新定義。組合狀态可以通過以下方式重新定義(擴充):

· adding new Regions,

增加新區域,

· adding Vertices and Transitions to inherited Regions,

向繼承區域中增加頂點和遷移,

· adding entry/exit/doActivity Behaviors, if the general State does not have any,

增加進入/退出/doActivity行為,前提是泛用狀态中沒有定義,

· redefining States and Transitions.

重新定義狀态和遷移。

The redefinition of a State applies to the whole StateMachine.

狀态重新定義的适用範圍是整個狀态機。

A submachine State may also be redefined. The submachine StateMachine may be replaced by another submachine StateMachine, provided that it has the same entry/exit points as the redefined submachine StateMachine. However, it may have additional entry/exit points.

子狀态機狀态也可以重新定義。子狀态機可以被另一個子狀态機代替,前提是代替者擁有被代替者所有的進入/退出點。但是代替者可以有額外的進入/退出點。

In case of multiple general Classifiers, extension implies that the extension StateMachine gets orthogonal Regions for each of the StateMachines of the general Classifiers in addition to a distinct new Region.

在擁有多個泛用類目的場合,擴充意味着擴充狀态機在擁有一個不同的新區域的同時,從每個泛用類目的狀态機處取得正交區域。

14.3.3.1.2 Transition redefinition(重新定義遷移)

A Transition of an extended StateMachine may in the StateMachine extension be redefined. Transitions can have their effect and target State replaced, while the source State and trigger are preserved.

擴充狀态機中的遷移也可以被重新定義,遷移效應行為和目标狀态可以被替換,但源狀态和觸發條件被保留。

14.3.4 Notation(記法)

A StateMachine that is an extension of the StateMachine in a general Classifier will have the keyword «extended» associated with the name of the StateMachine (e.g., see Figure 14.39 and Figure 14.40). Similarly, to indicate that an inherited Region is extended or that a State is extended, the keyword «extended» is added to the name of the element.

如果狀态機是泛用類目的狀态機的擴充,它的名稱在表示時會增加一個與名稱關聯的«extended»關鍵字(例子可以參照圖14.39和圖14.40)。類似的,為了表明繼承的區域是擴充的或狀态是擴充的,名稱之後也會增加«extended»關鍵字。

Inherited elements in a StateMachine, Region, or State are drawn either with dashed lines or light-toned lines (e.g., Figure 14.39). Finally, if a State is a leaf state (i.e., isLeaf = true), an additional label following the name of the State may be added consisting of the keyword «final».

狀态機,區域或狀态中繼承的元素使用虛線或淺色線描畫(參見圖14.39)。如果狀态是葉子狀态(即isLeaf為真),名字後面會增加一個額外的标簽,标簽包含«final»關鍵字。

14.3.5 Examples(示例)

As an example of StateMachine specialization, the States “VerifyCard,” “OutOfService,” and “VerifyTransaction” in the ATM StateMachine in Figure 14.38 have been designated as final, which means that they cannot be redefined in

specializations of ATM. All other States can be redefined. The (verifyTransaction-releaseCard) Transition has also been specified as final, meaning that its effect Behavior and the target State cannot be redefined.

作為狀态機特化的例子,圖14.38中狀态機包含的狀态“VerifyCard,” “OutOfService,” 和 “VerifyTransaction”已經被指定為final,這意味着它們在ATM特化時不能被重新定義。除此以外的所有狀态都可以被重新定義。遷移 (verifyTransaction-releaseCard)也被定義為final,意味着效應行為和目标狀态不能被重新定義。

EA&UML日拱一卒-活動圖::14.3 StateMachine Redefinition

Figure 14.38 A general StateMachine

In Figure 14.39 a specialized ATM (which is the StateMachine of a Class that is a specialization of the Class with the ATM StateMachine of Figure 14.38) is defined by extending the composite State by adding a State and a Transition, so that users can enter the desired amount. In addition, a Transition is added from an inherited State to the newly introduced State.

圖14.39中定義了特化的ATM(它是圖14.38中ATM狀态機的類特化以後得到的新類的狀态機),方法是通過增加狀态和遷移來擴充組合狀态,這樣使用者可以輸入期望的數量。另外就是,在繼承到的狀态和新引入的狀态之間增加了一個遷移。

EA&UML日拱一卒-活動圖::14.3 StateMachine Redefinition

Figure 14.39 An extended StateMachine

Figure 14.40 shows an example of adding Transitions to a specialized StateMachine.

圖14.40表示的是向特化的狀态機增加遷移的例子。

EA&UML日拱一卒-活動圖::14.3 StateMachine Redefinition

繼續閱讀