title: How do you pass instances created in main to classes?
body: <p>First, I apologize if this is a dumb question. This has been bothering me recently and I figured it was worth asking...</p>
  
  <p>I have an application where the classes flow like so:</p>
  
  <p><img src="https://i.stack.imgur.com/AmpAB.png" alt="enter image description here"></p>
  
  <p>I'm currently trying to allow my Client class and Server class to have access to instances of each other that are created in MyApp's main. The issue is that the instances are created in main (thus making them static) and I'm wondering how to properly pass them to the other classes as what I've done doesn't seem like it is the right way.</p>
  
  <p>Here is what I've done:</p>
  
  <pre><code>public class MyApp {
      private static RedClient red_client = null;
      private static BlueClient blue_client = null;
      private static RedServer red_server = null;
      private static BlueServer blue_server = null;
  
      public static void main(String[] args) {
          final Client myClient = new Client(arg1, arg2);
          red_client = myClient.getRedClient();
          blue_client = myClient.getBlueClient();
  
          final Server myServer = new Server(arg3, arg4);
          red_server = myServer.getRedServer();
          blue_server = myServer.getBlueServer();
      }
  
      public static RedClient getRedClient() {
          return red_Client;
      }
  
      public static BlueClient getBlueClient() {
          return blue_client;
      }
  
      public static RedServer getRedServer() {
          return red_server;
      }
  
      public static BlueServer getBlueServer() {
          return blue_server;
      }
  
  }
  </code></pre>
  
  <p>I would later make use of the following like so:</p>
  
  <pre><code>public class Client {
      public void SomeMethod {
          MyApp.getBlueServer.doSomething(myObject);
      }
  }
  </code></pre>
  
  <p>I'm just unsure if this is a proper way of passing the instance to the other class as Client and Server both communicate with MyApp. (Please ignore the class names as they have nothing to do with functionality of the application, I just used them as names because it was the first thing I could think of).</p>
  
  <p>If you need any clarification let me know, as I'm open to learning and criticisms. If this is the wrong way, can you please explain why it is wrong and then explain the proper way. </p>
  
  <p><strong><em>EDIT</em></strong></p>
  
  <p>Further clarification:</p>
  
  <ul>
  <li>MyApp has access to Client &amp; Server </li>
  <li>Client has access to RedClient &amp; BlueClient </li>
  <li>Server has access to RedServer &amp; BlueServer</li>
  </ul>
  
  <p>No other classes have access to each other.</p>