So I have to design a DTO in Java, in a way that I have a Profile which has many Roles. This DTO will be served to a front end application. So I create a class named ProfileDTO and a static inner class called Role.
public class Profile {
private List<Role> roles;
// ommiting getters/setters
public static class Role {
}
This way, if I want to create an instance of Role from outside I have to declare it like
var role = new Profile.Role();
I also saw another approach from a colleague of mine though. Have a separate Role class in the same package and just use
private List<Role> roles;
in Profiles class.
So which approach is better? And if it depends, what are the factors it depends on ?