Accesing variables and methods between classes using reference and singleton : <p>I'm struggling with using variables and methods between classes. For example, let's focus on variable only. I have two classes, <code>Foo</code> and <code>Bar</code>. I have constantly changing variable in <code>Foo</code> named <code>number</code>. How do I access this variable from class <code>Bar</code>? There will be always only one instance of <code>Bar</code> class.</p>

<pre><code>class Foo {
  private Bar bclass;
  public int number = 0;

  Foo() {
     bclass = new Bar();
  }
}

class Bar {
  Bar() {
    // code
    // Access Foo's number from here
  }
}
</code></pre>

<p>There are a few options that I can think of. First - Singleton pattern. I can make all methods and variables static, make constructor private and make only one instance. Second solution would be passing <code>number</code> as reference via constructor. But that doesn't solve my problem with accessing methods in <code>Foo</code>. Or i could pass whole instance of <code>Foo</code> to <code>Bar</code> via constructor like this:</p>

<pre><code> Bar(Foo firstClass) {}

 // Then in Foo
   bclass = new Bar(this);
</code></pre>

<p>My program is using 4 different classes, all of them will have always only one instance and all of them need to communicate with main class or between each other in some way (using it's variables or methods). Which approach would you recommend me? Making all 4 classes as Singletons?</p>

<p>Sorry if the title or text is confusing, if I missed something it something isn't clear I will gladly respond or edit my question.</p>
