title: Java, pass main class to child class, bad coding style?
body: <p>Please bear with me on this as I'm still getting the hang on Java.</p>
  
  <p>The example bellow reads from a Class named <code>Parent</code> that creates an instance of itself on the <code>main</code> method. It then makes that instance do all sorts of calculations.</p>
  
  <p>Next it fires up a thread named <code>Child</code> passing the <code>Parent</code> instance as a reference to <code>Child</code>.</p>
  
  <p>The <code>Child</code> just sits there monitoring things and, sometimes, fires up public methods on <code>Parent</code>.</p>
  
  <p>It works. The question is, <strong>is this poor style</strong>? Is there a more <em>Java thinking way</em> of doing this sort of work?</p>
  
  <pre><code>public class Parent {
  
      // main function that fires up the program
      public static void main() {
  
          // creates an instance of himself
          // and fires go that does all sorts of fuzzy calculus
          Parent parent = new Parent();
          parent.go();
  
          // creates a new thread of child and starts it
          Child child = new Child(parent);
          child.start();
      }
  
      private void go() {
          // all sort of initializations
      }
  
      public void getDataFromChild(int data) {
          // will get data from running child thread
      }
  }
  
  
  
  public class Child extends Thread {
      private Parent parent;
  
      // child constructor grabs Parent instance into "o"
      public Child(Parent o) {
          parent = o;
      }
  
      // this class main loop
      public void run() {
          while(1==1) {
              doSomething();
              try {
                  sleep(1000);
              }
              catch(Exception e) { }
          }
      }
  
      private void doSomething() {
          parent.getDataFromChild(1);
      }
  
  }
  </code></pre>
  
  <p>Thank you.</p>