Answer the question
In order to leave comments, you need to log in
When should you use DTO and when not?
It is not entirely clear and understandable when it should be used and when it really should be used.
Answer the question
In order to leave comments, you need to log in
in the right architecture in a good way - it must be used for each (conditionally) transfer of a data block between layers, but in practice it is often possible less often,
for example, a tool for java mapstruct.org
and there is an example
public class Car {
private String make;
private int numberOfSeats;
private CarType type;
//constructor, getters, setters etc.
}
public class CarDto {
private String make;
private int seatCount;
private String type;
//constructor, getters, setters etc.
}
those. it seems that almost the entire Car object (which may contain methods) is transferred using an intermediate CarDto - this can be at the junction between the data reading layer from the database to the application model layer, or between 2 independent layers like the player’s data model in the game and all of it units and passing it to the AI method that calculates the behavior of the bot
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question