【发布时间】:2020-08-21 02:22:57
【问题描述】:
考虑一个简单的状态机:
下面是BoUML从中生成的一段C++代码:
// 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();
}
}
请注意,_do(stm) 由 Sample::Sample_State::State1_State::exit_state1(Sample & stm) 调用,即在退出状态 1 时,就在调用退出行为 stm._sample_state._state1_state._doexit(stm); 之前
The UML Specification 告诉我们:
14.2.3.4.3 状态进入、退出和 doActivity 行为
。 . .
一个状态也可能有一个关联的 doActivity 行为。此行为在进入状态时开始执行(但仅在状态进入行为完成后)并与可能与状态关联的任何其他行为同时执行,直到:
- 完成(在这种情况下会生成完成事件)或
- 状态已退出,在这种情况下 doActivity 行为的执行将中止。
State 的 doActivity 行为的执行不受该 State 的内部转换触发的影响。
在_doentry(stm);之后从Sample::Sample_State::State1_State::create()调用_do(stm)不是更符合UML规范吗?
【问题讨论】:
-
你的结论似乎有道理。很确定布鲁诺会加入并评论/回答。
-
如果您无法编译自己的状态机生成器,请告诉我您在哪个操作系统上使用 BoUML,我会为您做的
标签: uml state-machine