title: Structuring parent and sub classes references
body: <p>I'd like to create multiple parents, each parent contains multiple children.
  The problem is that i want only one parent for each set of children, and each of the children must know about their parent and vice versa. Set of children share one instance of the parent - it's methods and variables. So if one of the children change parent variable, all of the rest children would get the same result.</p>
  
  <p><strong>Idea</strong></p>
  
  <p><a href="http://oi57.tinypic.com/6ohh7n.jpg" rel="nofollow">http://oi57.tinypic.com/6ohh7n.jpg</a></p>
  
  <p><strong>What i tried</strong></p>
  
  <ul>
  <li>using inheritance, but that resulted in creating separate parent object for each child, which is what i don't want.</li>
  <li>parent reference injection in child constructor, like this</li>
  </ul>
  
  <pre class="lang-java prettyprint-override"><code>//reference injection
  class Parent{
      public Parent(){
          children = new Child[10];
  
          for(int i = 0; i &lt; children.length; i++){
              children[i] = new Child(this);
          }
      }
  
      Child[] children;
  }
  
  class Child{
      public Child(Parent parent){
          this.parent = parent;                        
      }
  
      private Parent parent;
      public Parent getParent(){return parent;}
  }
  
  Parent parent = new Parent();
  Child child1 = new Child(parent);
  Child child2 = new Child(parent);
  Child child3 = new Child(parent);
  </code></pre>
  
  <p>But this doesn't feel solid, because i have to pass <strong>this</strong> in constructor and it doesn't feels like a good approach.</p>
  
  <p>What might be the best approach doing this?</p>
  
  <p>Thank you very much.</p>