mardi 25 février 2020

Duplicate logic in backend and frontend with Domain Driven Design

I have a class with some calculation login in backend:

public class MyDomainClass{
    private Double amount;
    private Double total;
    public Double getPercentage(){
        /*business logic*/
    }
}

My frontend is in angular 2+ and I want to show this information in 2 ways.

In a table with a list of them provided by the server:

enter image description here

And in a edition form, with the percentage calculation based on user input:

enter image description here

To make this calculation in the form I have to duplicate the logic in a frontend domain class too? I'm afraid to duplicate business logic and lost control of the code with more complex problems with this same idea (Some logic in backend for reports and list and the same logic in frontend forms).

How can I avoid that?

P.S: I use Jax-rs in the backend.

Aucun commentaire:

Enregistrer un commentaire