dimanche 20 septembre 2020

How to reduce duplicate code for calculations based on DTO and model classes

In one of our projects we have some sort of code duplication which we would like to get rid of: It is about code for the same calculations on both DTO and model classes.

E.g. we have the following 2 methods:

boolean isFreeShipping(CartDto cartDto) {
...
}
boolean isFreeShipping(CartModel cartModel) {
...
}

What is the best approach to solve this?

  • Have the calculation only for the model, and convert the DTO to the model if needed?
  • Or vice versa?
  • Introduce a specific value object which holds only the necessary fields and use this for the calculation - with mappers for both DTO and model?

Aucun commentaire:

Enregistrer un commentaire