When I create a Data transfer Object (DTO) which I use to store user input data to manager layer, I have a doubt that I’m doing it in correct way.
For example
Scenario one
public class Person{
private String name;
private int age; // primitive type
private double weight; // primitive type
}
Scenario 2
public class Person{
private String name;
private Integer age;
private Double weight;
}
in this case what is the best scenario that I can use and what are the factors that I should think about when decide on each scenarios. Kindly advice me.
If you can use a primitive type, I would use a primitive type. Not just for performance reasons but to make it clear that
nullis not a valid value.If you have a value which can be
null, use a wrapper.Also if you can make the fields
finalI would do so as well as this avoids questions of mutability and thread safety.