mercredi 19 août 2020

How can I refactor my java code with multiple if conditions

We have a java code with multiple if conditions(actual code has more than 100 if conditions) to call appropriate methods depending upon the operation name. How can this be refactored in more efficient way?

  if ("Customer".equals(header.getString(OPERATION))) 
    CustomerRequest searchRequest = gson.fromJson(paylaod, CustomerRequest.class);
    response = viewCustomerServiceEndpoint.viewCustomer(searchRequest, pool);
  }
  if ("ProfileUpdate".equals(header.getString(OPERATION))) {
    ProfileUpdateRequest searchRequest = gson.fromJson(paylaod, ProfileUpdateRequest.class);
    response = saProfileUpdateEndPoint.saProfileUpdate(searchRequest, pool);
  }

Aucun commentaire:

Enregistrer un commentaire