Can data classes contain methods for validation?

Posted by Arturas M on Programmers See other posts from Programmers or by Arturas M
Published on 2012-10-23T21:48:44Z Indexed on 2012/10/23 23:17 UTC
Read the original article Hit count: 220

Filed under:
|

OK, say I have a data class for a user:

public class User {
private String firstName;
private String lastName;
private long personCode;
private Date birthDate;
private Gender gender;
private String email;
private String password;

Now let's say I want to validate email, whether names are not empty, whether birth date is in normal range, etc. Can I put that validation method in this class together with data? Or should it be in UserManager which in my case handles the lists of these users?

© Programmers or respective owner

Related posts about data

Related posts about validation