我有一个代表注册过程中的一个步骤的类。当用户在填写完步骤后单击保存,然后执行我希望在注册过程结束时执行步骤时执行的其他操作以及在步骤中调用保存时,我希望某些步骤可以执行。那个阶段。我决定使用拥有一个国家的想法,但它似乎有一个糟糕的代码味道。有关如何改进此设计的任何意见?OO设计问题
public class Step1
{
public Enum State
{
InProcess = 1,
EndProcess
}
private State processState;
public Step1(State currentState)
{
processState = currentState;
}
public bool IsValid()
{
bool result;
if(processState = State.InProcess)
{
result = PerformCheck1();
}
else if(processState = State.EndProcess)
{
result = PerformCheck2();
result = PerformCheck3();
}
else
{
throw new Exception("Cannot determine process state");
}
return result;
}
public void Save()
{
if(processState = State.InProcess)
{
DoThing1();
}
else if(processState = State.EndProcess)
{
DoThing2();
DoThing3();
DoThing4();
}
else
{
throw new Exception("Cannot determine process state");
}
}
}
属于codereview。 – 2012-02-25 14:36:26