my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Implementing one to many relationships Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Implementing one to many relationships" Watch "Implementing one to many relationships" New topic
Author

Implementing one to many relationships

John Uhlig
Greenhorn

Joined: May 12, 2003
Posts: 13
Let's say I have a Person class and an Address class. Assume that one person can have multiple addresses. I am thinking that I would put an array or a collection variable on the person and then populate it with Address objects. Is this the generally accepted way of doing it or is there something I am missing?

FYI - I am tyring to create a very simple Rolodex type program just to teach myself some Java skills.

Thanks,
John
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
Sure, you could do that. A class data member can be another class. I'd consider using a scalable array, such as ArrayList, but there is some additional overhead. For a Rolodex type of progam, the overhead wouldn't really matter much unless your targeting portable devices like Palm or CE.


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Implementing one to many relationships
 
Similar Threads
n+1 selects in birectional one to one association
Hibernate Inheritance Mapping Question !
instanceof error
XML: Unique
Question on ejbCreate().