I have code which looks like this:
if(XisNotY && DoStep1AndChangeXtoY()){
if(AisNotB && DoStep2AndChangeAtoB(){
if(IisNotJ && DoStep3AndChangeItoJ(){
if(PIsNotQ && DoStep4AndChangePtoQ(){
}
}
}
}
Now if Step3 fails, I want to fix external issues and re-run the process so that it can be taken to completion. This won't happen with the current implementation. I can take the first part of each condition out and do something like:
if(XisNotY && DoStep1AndChangeXtoY()){
}
if(XisNotY && AisNotB && DoStep2AndChangeAtoB()){
}
if(XisNotY && AisNotB && IIsNotJ && DoStep3AndChangeItoJ()){
}
if(XisNotY && AisNotB && IIsNotJ && PIsNotQ && DoStep4AndChangePtoQ()){
}
But it doesn't seem to be elegant. What is the best way to refactor this piece so that the conditions are re-runnable? Also, note that DoStep.. methods are not the same signature. They are all quite different method calls.
Edit: Clarification: This is part of a service endpoint code. Failure would mean throw exception and return. The re-run needs to happen in a new call to the same endpoint.