title: MVC with DAO/VO - Which DAO should the Controller talk to?
body: <p><strong>Background:</strong></p>
  
  <p>I have a design pattern problem that I was hoping someone may be able to solve. I program in PHP but I believe DAO/VO is popular in Java.</p>
  
  <p>I have been using MVC for many years now. I designed a shopping that was MVC but used procedural programming. Thus recently I decided to develop the cart again, using OO.</p>
  
  <p><strong>Problem:</strong></p>
  
  <p>The problem I was faced with was that my Product class did not make sense to have a RetrieveAll() method.
  E.g. If I had 10 products listed, from which instance would I call the RetrieveAll() method? I would have 10 choices.</p>
  
  <p><strong>Solution:</strong></p>
  
  <p>Thus, I found the DAO/VO pattern.
  Unless I have not researched this pattern enough - I believe that each DB table must have a Model + DAO. No model or DAO should know about another set of models or DAO's. Thus being encapsulated.
  The pattern makes perfect sense, pulling the database layer away from the Model.</p>
  
  <p>However. In the shopping cart, my products are assigned categories. 
  A category could be electronics, clothing, etc.</p>
  
  <p>There are 3 tables:
  - Category (pid, name)
  - Category Item (iid, name)
  - Category Link (pid, iid)</p>
  
  <p>From an MVC approach, it doesn't make sense of which DAO the controller should be talking to?</p>
  
  <p>Should it be:</p>
  
  <ul>
  <li>The controller talks to all 3 DAO's and then return the appropriate data structure to the View?</li>
  <li>Or should the DAO's talk to one-another (somehow) and return a single structure back to the Controller?</li>
  </ul>
  
  <p><a href="http://imagepaste.nullnetwork.net/viewimage.php?id=3349" rel="nofollow">Please see here for example (image)</a></p>