-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Where to place add/remove methods for set?
PostPosted: Sat Apr 15, 2006 8:56 am 
Newbie

Joined: Wed Apr 12, 2006 11:53 am
Posts: 13
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 15, 2006 9:13 am 
Newbie

Joined: Sat Apr 15, 2006 4:50 am
Posts: 9
From the OO-perspective I'd definitely put the methods into your User class. You could for instance inherit from the auto-generated class and put your custom code in there, so that you don't loose it on re-creation.

Cheers,
Volker


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 15, 2006 11:25 am 
Newbie

Joined: Wed Apr 12, 2006 11:53 am
Posts: 13
OK, I guess that makes sense. Unfortunately, the code generation will produce both the abstract class and the concrete class (using MyEclipseIDE). I suppose I could extend the concrete class and add the functions that way.

Cheers,

M.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.