Ok so I currently need to refactor a class and in best case use a Design Pattern. I want to do this, to demonstrate, how you can refactor the Legacy Code, to serve the SOLID-Principles.
How ever until now, all I was able to do, was to extract Methods. I have one Code-Fragment right here, which basically fills one Object with Data from another Object:
try {
final Object response = service.getOutput(InputData);
if (response instanceof OutputData) {
final OutputData output = (OutputData) response;
data.Quantity(output.getQuote().getQuantity());
data.setDate(output.getQuote().getDate());
data.setMaterial(productData.getCode());
if (isValidCustomer(output.getQuote())) {
data.setName(output.getQuote().getName());
} else {
data.setName("");
}
if (output.getQuote().getLimit() != null) {
data.setLimit(output.getQuote().getLimit().trim());
}
}
catch (final Exception e){
//...
}
if (productPrice != null) {
data.setProductPrice(productPrice);
data.setTotalPrice(calculateTotalPrice(data, productPrice, quantity));
}
What would be a Design Pattern you could use in this case? The problem is, the project is based on Spring, so it doesn't really deal with constructors. And as you can see there are already some extracted Methods, like calculateTotalPrice and so on.
Aucun commentaire:
Enregistrer un commentaire