In MVC (I'm using Spring, although it's not relevant to the discussion) I have a following model:
public class User {
private Long userId;
private String username;
private String password;
private String passwordRepeat;
private String email;
private boolean rememberLogin;
/// ctors, setters and getters [...]
}
This model is used during both registration and login and therefore contains a sum of fields for both purposes. In particular - passwordRepeat
is completely not relevant during login and vice versa - rememberLogin
is unused during registration. It was all fine up to the point when I started adding validation (javax.validation) as annotation to the fields. For example I want to put constraints on passwordRepeat
so that it is not null and witin given size range, however it will inevitably be null during login validation.
Should a model like this that serves multiple purposes be split into multiple objects (for example: UserLoginData, UserRegistrationData and User) or is there a better way of approaching this?