Reputation: 143
In the state pattern how is this modeled ?
state A to state B on trigger X and conditon C1 when current state is A
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.
Upvotes: 2
Views: 3885
Reputation: 9952
That's pretty standard see e.g. this example.
[Edited on basis it's not homework!]
Assuming I understand right:
X
) which can trigger one of two possible transitionsC1
or C2
)If so that's a standard case for using guard conditions. The syntax would be:
X[C1]
as the label on the transition A->B, and X[C2]
on the transition A->C.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]
.
For it to be semantically correct, C1 & C2 must be mutually exclusive in state A - otherwise you have non-determinism.
hth.
Upvotes: 1