I came across a DTO class like the below one.
class PersonDTO {
private String firstName;
private String middleName;
private String lastName;
private String dob;
// some 50 fields more
private List<PersonDTO> persons;
//getters and setter
}
Question 1: Is it a good practice to have such huge DTO classes with so many properties?
Question 2: Is it a good practice to have a DTO class having an ArrayList of its own type? Wouldn't it cause a circular reference?
Update:
I work for a product in Healthcare domain. The use case is to generate a report of all the users in the system. Along with the list of users, the report also needs to show the summary information. The data need to be serialized, because the UI is expecting a JSON response.
Below is the actual DTO I was taking about.
A method was written in DAO class, which returns a UserDTO object. This UserDTO object that is being returned.. consists of a List of all users, and some summary information like: total doctors, total nurses etc.
class UserDTO{
private String userID; //This is unique
private String firstName;
private String middleName;
private String lastName;
private String dob;
private String userType; // value can be DT(for doctor), ST(for nurse),
private int totalDoctorCount; //Holds the total number of UserDTOs with userType value set to DT in the ArrayList of users.
private int totalNurseCount; //Holds the total number of UserDTOs with userType value set to ST in the ArrayList of users.
// there are some 40 more properties.
private List<UserDTO> users;
//In this class there are also properties like below...
private String primaryAddrStreetName;
private String primaryAddrCity;
private String primaryAddrState;
private String primaryAddrCountry;
private String primaryAddrZipcode;
private String billingAddrStreetName;
private String billingAddrCity;
private String billingAddrState;
private String billingAddrCountry;
private String billingAddrZipcode;
private String shippingAddrStreetName;
private String shippingAddrCity;
private String shippingAddrState;
private String shippingAddrCountry;
private String shippingAddrZipcode;
}
Question 3: Is this DTO design apt for that use case? if not, then what would you suggest?
Question 4: The user has multiple addresses. But, Shouldn't the address details be in its own class (something like UserAddressDTO) and then we should add an array/ArrayList of UserAddressDTO in UserDTO??
Question 5: Also please give some insight about how would such kind of DTOs effect the JVM memory. The report would fetch thousands of records.
PersonDTO
has a list ofPersonDTO
s. I don't usually think of "persons" as being one of the properties that a person has.