In our application, I saw code written as follows:
User.java (user object)
public class User
{
protected String firstName;
protected String lastName;
...
getters/setters (regular POJO)
}
UserSearchCommand
{
protected List<User> users;
protected int currentPage;
protected int sortColumnIndex;
protected SortOder sortOrder;
protected User user;
public String getFirstName()
{return(user.getFirstName());}
public String getLastName()
{return(user.getLastName());}
}
Now, in my experience, this pattern or anti-pattern looks bad for me. First, we mix several issues together. Although they are all user-related, it differs from the typical POJO design. If we are going to go this route, shouldn't we do it?
UserSearchCommand
{
protected List<User> users;
protected int currentPage;
protected int sortColumnIndex;
protected SortOder sortOrder;
protected User user;
public User getUser()
{return(user);}
}
Just return the user object, and then we can call any methods on it at our discretion?
Since this is very different from a typical bean design, the JSR 303, bean check does not work for this model, and we must write validators for each bean.
Does anyone else see something wrong with this design template or am I just picking on a developer?
Walter
Walter White