Comunicating between Objects
<p>I don't know what's the best practice for this.
Let's say I have some hierarchical objects:</p>

<pre><code>Neighborhood
Family
</code></pre>

<p>So each Family lives in a Neighborhood.
The objects are mapped like this:</p>

<pre><code>class Neighborhood {
  public $id;
  public $name;

  public $nr_families;
}

class Family {
  public $id;
  public $name;
  public $neighborhood_id;
}
</code></pre>

<p>Each Object models it's own database table. All objects of a type are kept in an array in the global scape, so there are 2 arrays.</p>

<p>How can I know, FROM INSIDE the Neighborhood object, at the CREATION DATE, how many Families are in that Neighborhood, without quering the database again or accessing the global array of Families? Let's say the Family array was generated first, they are already there, and now when I generate the Neighborhood array, these objects need to have a property with the total number of families in each. This property doesn't match a database field, it has to be calculated on the fly.</p>

<p>Is there a design pattern? Should I use some kind of third object?</p>
