我只是在玩弄“状态设计模式”,并且对状态机中的错误处理方式有几个问题。下面就让我们状态设计模式:错误处理
class state_machine
{
private:
state state1;
state state2;
public:
}
class state
{
private:
state_machine* m_state_machine; /** Will pass the pointer to states **/
public:
void perform_state1_action();
void perform_state2_action();
}
class state1: public state
{
public:
void perform_state1_action()
{
/**
Functionality
**/
}
void perform_state2_action(); // Have nothing to do for this function
}
class state2: public state
{
public:
void perform_state2_action()
{
/**
Functionality
**/
}
void perform_state1_action(); // Have nothing to do for this function
}
的情况下我的问题是我怎么妥善处理的情况下,我们称之为perform_state2_action当其在状态1。我是否写了一个没有任何功能或可能有错误记录功能的基本函数实现?
为什么state_machine有两个状态成员时,都出现能够执行这两个州。 – 2014-11-20 22:35:18