私は登録プロセスの一歩を表すクラスを持っています。私はステップを記入した後にユーザーが保存をクリックした後、私たちがステップを実行して、登録プロセスの終了時にステップを実行したいと思っている他のものを、ステップその段階。私は州があるというアイデアを使用することに決めましたが、悪いコードの臭いがあるようです。このデザインを改善する方法に関するコメント?コードと他の問題を無視オブジェクト指向設計の問題
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に属します。 –