I am trying to model some states in my file generation program,
at one point :
- I want to check the current status of the data
- if data is valid I want to continue
- otherwise I want to inform the user of the reason why I cannot continue
A psudocode would be like:
if(isValid()){
writeFile()
} else {
switch(getReason()){
case FAIL1: doSomething1();
break;
case FAIL2: doSomething2();
break;
case FAIL3: doSomething3();
break;
}
}
Not sure if an approach like this is correct, would like your advice/opinions. Where: in total there are less than 10 error states, and only one error state is applicable at a given time.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…