Consider a simple StateMachine:
Below is a fragment of C++ code generated by BoUML from it:
// to manage the event create
void Sample::Sample_State::State1_State::create(Sample & stm) {
_doentry(stm);
}
// perform the 'entry behavior'
void Sample::Sample_State::State1_State::_doentry(Sample & stm) {
stm.enter_state1();
}
// perform the 'exit behavior'
void Sample::Sample_State::State1_State::_doexit(Sample & stm) {
stm.exit_state1();
}
// perform the 'do activity'
void Sample::Sample_State::State1_State::_do(Sample & stm) {
stm.do_state1();
}
// to manage the event exit_state1
void Sample::Sample_State::State1_State::exit_state1(Sample & stm) {
_do(stm);
{
stm._sample_state._state1_state._doexit(stm);
stm._set_currentState(stm._sample_state);
stm._final();
}
}
Note that _do(stm)
is called by Sample::Sample_State::State1_State::exit_state1(Sample & stm)
, i.e. on the exit from State 1, just before the call of the exit behavior stm._sample_state._state1_state._doexit(stm);
The UML Specification tells us:
14.2.3.4.3 State entry, exit, and doActivity Behaviors
. . .
A State may also have an associated doActivity Behavior. This Behavior commences execution when the State is entered (but only after the State entry Behavior has completed) and executes concurrently with any other Behaviors that may be associated with the State, until:
- it completes (in which case a completion event is generated) or
- the State is exited, in which case execution of the doActivity Behavior is aborted.
The execution of a doActivity Behavior of a State is not affected by the firing of an internal transition of that State.
Wouldn't it be more aligned with UML specification to call _do(stm)
from Sample::Sample_State::State1_State::create()
, right after _doentry(stm);
?