user716129
user716129

Reputation: 143

state machine with self transition but different entry actions

I have a state machine, where

S1--->inp X, guard condition = Y---->S1 (self transition to S1 after executing, action1()

S1--->inp X, guard condition = !Y---->S1 (self transition S1 after executing, action2()

So the only difference between the two inputs is that it is executing a different action,

I feel something is wrong here, should I be doing something different ?

Upvotes: 1

Views: 1256

Answers (1)

sfinnie
sfinnie

Reputation: 9960

You can't have two alternate entry actions in the same state. Whole point is the state is independent of the route you got there. You have two options:

  1. Put the actions on the transitions. UML allows a transition to have 3 parts:
    • a triggering event
    • a guard condition
    • an action executed if the event occurs and the guard is true. The action is completed before the transition to the target state occurs.
  2. Create 2 further states, one for each of action1() & action2(). State S1 would have two exiting transitions, one to each of the new states. Transition 1 would be labelled X[Y] and lead to state containing action1(). Similar for action2(). Each new state would have a transition back to S1 which was executed as soon as the action was complete.

Which you choose is largely stylistic if the diagram is conceptual. If you're translating directly to code then you'll need to consider semantics. Option (1) is more concise visually, however it means the transition will not be 'instantaneous'. For some environments - especially real-time / embedded - that may be significant.

hth.

Upvotes: 2

Related Questions