title: Appropriate way to pass instance of class to other classes (Java)
body: <p>I have a main class which has a number of instance related methods that are often needed in other classes and I often find myself passing an instance of the main class in the constructor. I often find this goes several layers deep with classes having instances of the main class that has been copied from instance to instance which I can't imagine is good for memory usage.</p>
  
  <p>Is there a way to do this without having to pass the instance in the constructor or a method or at least a way to reduce the memory that is used by the instances of the main class.</p>
  
  <p>To make it clear I am not looking for static methods, it is designed to be able to have more than one instance of the main class.</p>
  
  <p>Example code:</p>
  
  <pre><code>public class Main {
      public Main() {
          Class2 class2 = new Class2(this);
      }
  
      public void someMethod() {
          //Do something
      }
  }
  
  public class Class2 {
      private final Main instance;
  
      public Class2(Main instance) {
          this.instance = instance;
          Class3 class3 = new Class3(instance);
      }
  }
  
  public class Class3 {
      private final Main instance;
  
      public Class3(Main instance) {
          this.instance = instance;
          instance.someMethod();
      }
  }
  </code></pre>