title: Simple OODesign question: how to query data from multiple objects?
body: <p>I have been assigned the task of refactoring a legacy database application and I am trying to create objects that incapsulate the old code. It is the first time I use real OODesign, for now I just used OO to encapsulate some legacy login and refactor a subset of functionalities from an application.  <em>(Now it is the classic client server app with all the business logic in the UI, the idea is to make it multilayer in order to use the clients against an application server and eventually write a web interface.)</em></p>
  
  <p>I'll make an simplified example to explain what I want to accomplish:</p>
  
  <p>I have many instances of this class:</p>
  
  <pre><code>type
    TCustomer = class(TObject)
    private
      FOrders: TList&lt;TOrder&gt;; // or how do implement this?
      // the idea is that the TCustomer "owns" the TOrder, anyway in the 
      // legacy DB I just have an orders table with FK to the customer table
      // not the contrary. 
      // But if I do that the Customer object "loses" the TOrders???
      [...] // Many other fields
    public
      [...]
    end;
  </code></pre>
  
  <p>How do I query the Orders of all the customers? Imagine I want to query all the orders from September 2007.</p>
  
  <p>If I have 10000 <code>TCustomer</code> objects I don't want for sure to create them all (that means retrieveing them all from the database: I would retrieve too many info I don't need).</p>
  
  <p>In the current software of course it is done with a simple query to the orders table.</p>
  
  <p>But how this is accomplished in the OO world?</p>
  
  <p>Which is the approach you suggest me?</p>
  
  <p>Moreover: in refactoring a this kind of database applications do you suggest using an ORM (that means creating a new database and migrating all the data) or simply use existing DB (that is not bad in my case)?</p>