Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing one to many relationships

 
John Uhlig
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic