防护条件不同的状态转换 [英] state transition with different guard condition
问题描述
在状态模式下如何建模?
In the state pattern how is this modeled ?
状态A到触发器X和状态C1上的状态B,当前状态为A
state A to state B on trigger X and conditon C1 when current state is A
当当前状态为A时,状态X会在触发器X和状态C2上变为状态C
state A to state C on trigger X and condition C2 when current state is A
通常如何完成?我有很多可能需要实施的警卫条件.
how is this usually accomplished ? I have a lot of guard conditions that I may need to implement.
推荐答案
这很标准,例如参见此示例.
[不是根据功课编辑的!]
假设我理解正确:
- 您有一个事件(
X
),可以触发两个可能的过渡之一 - 根据适合的条件(
C1
或C2
)选择向哪个火场过渡
- You have one event (
X
) which can trigger one of two possible transitions - Selecting which transition to fire is made according to which condition holds true (
C1
orC2
)
如果是这样,这是使用保护条件的标准情况.语法为:
If so that's a standard case for using guard conditions. The syntax would be:
-
X[C1]
作为过渡A-> B上的标签,并且 -
X[C2]
在A-> C过渡上.
X[C1]
as the label on the transition A->B, andX[C2]
on the transition A->C.
C1& C2必须计算为布尔值,因此可以根据您的注释替换var==2
.即标签将变为X[var==2]
和X[var==3]
.
C1 & C2 must evaluate to booleans, so it would be fine to substitute var==2
as per your comment. i.e. the labels would become X[var==2]
and X[var==3]
.
为了使其在语义上正确,C1& C2在状态A中必须互斥-否则您将无法确定.
For it to be semantically correct, C1 & C2 must be mutually exclusive in state A - otherwise you have non-determinism.
hth.
这篇关于防护条件不同的状态转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!