mercredi 7 octobre 2020

Design pattern for nested if/else blocks

if (condition related to A) {
    //do
    if (condition related to B) {
        //do2
        if (condition related to c) {
            //do3
        }
        else if (condition related to C) {
            //do4
        }
    }
}
else if (condition related to A) {
        //do4
}
else if....

Is there a design pattern I can use to improve this code? I tried the strategy pattern using a map but it is limited to the outer if/else. What about inner the if/elses? Should I use same pattern there as well?

I checked many answers but they are limited to the outer if/else.

Aucun commentaire:

Enregistrer un commentaire