1

In UML statecharts, an event may how zero or more "parameters" (i.e., additional data associated with the event). The classic example would be a key press event with a parameter containing the key that was pressed.

When designing state machines, I often come across the following scenario. An event with parameters is received by a state. This event needs to trigger a transition to a new state. However, the new state's behavior is affected by the values of the parameters from the event.

Currently, I solve this problem by introduce extended state variables in which to "store" the event parameters. The first state stores the relevant event parameters into these variables then performs the transition. The second state then accesses these extended state variables. However, this can get messy quickly since I am adding extended state. In addition, many of these extended state variables are not used by the majority of states so the are "wasted."

My question is, is there a better way to solve this type of problem? If extended state is the correct way to go, how do you correctly model extended state variables in UML statechart diagrams?

2
  • 1
    How do you use the UML state charts? Are they a tool for communicating with other developers or do you generate code from them that gets deployed as-is? Jan 12 at 7:20
  • @BartvanIngenSchenau I only use them as a tool to communicate to other developers. Jan 12 at 14:57

1 Answer 1

2

When designing state machines, I often come across the following scenario. An event with parameters is received by a state. This event needs to trigger a transition to a new state. However, the new state's behavior is affected by the values of the parameters from the event.

As you are creating those state charts as a communication tool, you can leave some "implementation details" unmentioned. For example, you can show that the event carries a parameter by writing event(parameter) on the transition that is taken when the event occurs. You can then, for example, manipulate that parameter in actions within the state (or on an outgoing transition), without explicitly mentioning that the parameter gets stored and how it gets stored.

A computer would be confused about that detail of the parameter storage, but a human would understand that that is something that needs to happen but is left out for clarity.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.