title: Java design: Component, Model, Function
body: <p>I have three types of objects:</p>
  
  <ul>
  <li>Components: identified by a package and a name</li>
  <li>Models: identified by a package and a name</li>
  <li>Functions: identified by a name</li>
  </ul>
  
  <p>The relationships are defined as follows:</p>
  
  <ul>
  <li>A Component can have zero or more Model(s) [0..*]</li>
  <li>A Model can have zero or more Function(s) [0..*]</li>
  <li>A Function can be in one or more Model(s) [1..*]</li>
  <li>A Model can be in zero or more Component(s) [0..*]</li>
  </ul>
  
  <p>The natural design would be to have Component to have a set of references to Model(s) and Model to have a set references to Function. With this design I can easily navigate relationships in a top-down fashion (and easily answer queries like: "What Function(s) are contained in this Model?". </p>
  
  <p>The problem is that I need more flexibility.
  I would like to have something that's easily navigable to answer these kind of queries:</p>
  
  <ol>
  <li>Given a Function name, in which Models and in turn in which Components is this Function referenced?</li>
  <li>Given a Model package+name, in which Components is that Model referenced?</li>
  <li>Are there Models not referenced by any Component?</li>
  </ol>
  
  <p>I've thought of having Component, Model and Function as simple POJOs and to keep track of references between them with multiple HashMaps (<code>HashMap&lt;Component, Model&gt;</code>, <code>Hashmap&lt;Model, Component&gt;</code>, <code>HashMap&lt;Model, Function&gt;</code>, <code>HashMap&lt;Function, Model&gt;</code>) but this seems inefficient to me.</p>
  
  <p>Can you suggest me something better designed?</p>