Dear all,
Assuming I have a one-to-many association, e.g. a class User which has a Set of e-mail addresses. This class is auto-generated from a database and would look something like:
Code:
public class User
{
private Set emails = new HashSet(0);
public Set getEmails() {
return this.emails;
}
public void setEmails(Set e) {
this.emails = e;
}
// more stuff here...
}
I am just wondering where to place add/remove methods, e.g. addEmail() and removeEmail. Would you best place them in the class directly, like user.addEmail(), implemented as:
Code:
public void addEmail(String e) {
this.getEmails().add(e);
}
Or would you rather create a separate class, say UserManager with a method addEmail(User u, String e), implemented as:
Code:
public void addEmail(User u, String e) {
u.getEmails().add(e);
}
Sorry, if this is really basic stuff (and not really directly related to Hibernate). The second method is a bit more cumbersome and not as intuitive, but in the first method I'd have to recreate the method, if for any reason I have to re-generate the code of the classes.
Cheers,
M.