title: Modelling Related Objects
body: <p>I'm designing an application which deals with two sets of data - Users and Areas.  The data is read from files produced by a third party.  I have a User class and an Area class, and the data is read into a Users array and an Areas array (or other appropriate memory structure, depending on the technology we go with).</p>
  
  <p>Both classes have a unique ID member which is read from the file, and the User class contains an array of Area IDs, giving a relationship where one user is associated with many Areas.</p>
  
  <p>The requirements are quite straightforward:</p>
  
  <ul>
  <li>List of Users</li>
  <li>List of Areas</li>
  <li>List of Users for Specified Area</li>
  <li>List of Areas for Specified Users</li>
  </ul>
  
  <p>My first thought was to leave the data in the two arrays, then for each of the requirements, have a seperate method which would interrogate one or both arrays as required.  This would be easy to implement, but I'm not convinced it's necessarily the best way.</p>
  
  <p>Then I thought about having a 'Get Areas' method on the User class and a 'Get Users' member on the Area class which would be more useful if for example I'm at a stage where I have an Area object, I could find it's users by a property, but then how would a 'Get Users' method on the Area class be aware of/have access to the Users array.</p>
  
  <p>I've had this problem a number of times before, but never really came up with a definitive solution.  Maybe I'm just making it more complicated than it actually is.  Can anyone provide any tips, URLs or books that would help me with this sort of design?</p>
  
  <p>UPDATE:
  Thank you all for taking your time to leave some tips.  Your comments are very much appreciated.</p>
  
  <p>I agree that the root of this problem is a many-to-many relationship.  I understand how that would be modelled in a relational database, that's pretty simple.</p>
  
  <p>The data I receive is in the form of binary files from a third party, so I have no control over the structure of these, but I can store it whichever way is best when I read it in.  It is a bit square pegs in round holes, but I thought reading it in then storing it in a database, the program would then have to query the database to get to the results.  It's not a massive amount of data, so I thought it would be possible to get out what I need by storing it in memory structures.</p>