I have these long if - else/switch statements, really long, and they make the code hard to read. So was just wondering is there a way to get rid of them? Maybe something like using a class for each condition and then using chain of responsibility pattern ?
What kind of approach would you suggest ?
Here is a sample code:
if ( cc == LIB_DEFINED_CONSTANT_1 )
{
response = "-1";
errorWindow->setText ( "The operation timed out.\nPlease try again later." );
errorWindow->show ( );
}
else if ( cc == LIB_DEFINED_CONSTANT_2 )
{
response = "-1";
errorWindow->setText ( "Couldn't conect to the server.\nPlease try again later." );
errorWindow->show ( );
}
else if ( cc == LIB_DEFINED_CONSTANT_3 )
{
response = "-1";
errorWindow->setText ( "Access is denied.\nPlease contact our support team." );
errorWindow->show ( );
}
else if ( cc == LIB_DEFINED_CONSTANT_4 )
{
response = "-1";
errorWindow->setText ( "Credentials and varified\nPlease contact our support team." );
errorWindow->show ( );
}
else if ....
As you can see, most of the code in the conditional tag is some what similar, except for setting text for errorWindow.
EDIT : It would be nice if people can leave comment on why they down voted.