title: Methods to link common class attributes between objects? (not inheritance)
body: <p>I have a number of objects of the same class, each holding different data. </p>
  
  <p>However, they have a number of attributes that should be 'common' - i.e. set to the same value across all objects. (this could be a numeric value, a reference to another object etc etc)</p>
  
  <p>What are different methods of implementing this?
  A couple of methods I thought of:</p>
  
  <p>A dictionary containing all the objects and the common attributes as separate key/value pairs. The problem here is that the objects are dynamically created (there is a variable number of objects read from file) so creating keys could be a problem</p>
  
  <p>A 'collection' class, where the common attributes are defined in this collection class and the group of objects is passed in as a list</p>
  
  <p>I can't help feeling that there might be alternatives out there, or 'better' methods (I know that is subjective, but I'd like to know all possibilities...)</p>
  
  <p><strong>Edit:</strong>.</p>
  
  <p>Here is my specific example.</p>
  
  <p>I have a number of objects, each defining the branch of a river (from now on called <code>Branches</code>. So, they all have different x,y point attributes.</p>
  
  <p>They should all be 'linked' to another object, in this case an object describing the elevation over the domain (from now on called <code>DEM</code>) </p>
  
  <p>One way to do it could be a 'collector' class (call it <code>Network</code>) which groups together all the <code>Branches</code> objects and has an attribute which is a reference to the DEM.</p>
  
  <p>This way, I can safely use the <code>DEM</code> in all calculations using <code>Branches</code>. However, it is not ideal. I would like each <code>Branches</code> object to have a method which returns the elevation at each point. For that, <code>DEM</code> needs to either be passed into the <code>Branches</code> method (meaning I cannot define that method as a property, which I would like to do) or there needs to be an attribute within each <code>Branches</code> object pointing to <code>DEM</code>. The second method runs the risk of allowing separate instances of <code>DEM</code> to be referenced within each <code>Branches</code> object, which I don't won't to allow. It also seems a bit silly to have each <code>Branches</code> object holding a separate reference to the same thing (1 global reference would be preferred - this way I can change it without having to go through each <code>Branches</code> object). </p>
  
  <p>I find this kind of thing cropping up all over - I have a load of instances of the same object, but I want to keep some attributes common between them - so more general answers are preferred..</p>