samedi 11 mai 2019

What is the best way to eliminate many if-else conditions?

We are persisting an object in the database, But before there are few conditions that need to be checked I am using if-else to perform these what is the best way to eliminate if-else statements.

if(isNew){
    if(checkCreatePermission()){
       if(checkDuplicate()) {
          return foundObejct();
       } else {
           persistNewObject();
       }
    } else {
        throw new Exception();
    }
} else {
    if(checkCreatePermission()){
        udapteObject();
    } else {
        throw new Exception();
    }

}


Aucun commentaire:

Enregistrer un commentaire