これらの長い if - else/switch ステートメントが非常に長く、コードが読みにくくなっています。それで、それらを取り除く方法があるのだろうかと思っていましたか?たぶん、各条件にクラスを使用してから、一連の責任パターンを使用するようなものでしょうか?
どのようなアプローチをお勧めしますか?
サンプルコードは次のとおりです。
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 ....
ご覧のとおり、条件付きタグのほとんどのコードは、errorWindow のテキストを設定することを除いて、似たようなものです。
編集: 反対票を投じた理由についてコメントを残していただければ幸いです。