lundi 7 janvier 2019

java Refactoring if else

I have this if else code, I was wondering if there is more useful/intelligent way for writing it :

public void saveContent() throws Exception {
   if(book.isColored()) {
      book.setChoosen(“1234”);
   } else if (book.isAvailable()) {
      book.setChosen(“23498”);
   } else if (book.isAdults()) {
      book.setChosen(“0562”);
   } else {
      ReaderResponse response = reader.getReaderResponse();
      if (response != null) {
         book.setChosen(response.getName());
         }
      } else {
            book.setChosen(“4587”);
      }
   }
}

The method returns void.

Aucun commentaire:

Enregistrer un commentaire