Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8266305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:06:43+00:00 2026-06-08T05:06:43+00:00

First, I apologize if this is a dumb question. This has been bothering me

  • 0

First, I apologize if this is a dumb question. This has been bothering me recently and I figured it was worth asking…

I have an application where the classes flow like so:

enter image description here

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.

Here is what I’ve done:

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;
    }

}

I would later make use of the following like so:

public class Client {
    public void SomeMethod {
        MyApp.getBlueServer.doSomething(myObject);
    }
}

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).

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.

EDIT

Further clarification:

  • MyApp has access to Client & Server
  • Client has access to RedClient & BlueClient
  • Server has access to RedServer & BlueServer

No other classes have access to each other.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:06:46+00:00Added an answer on June 8, 2026 at 5:06 am

    I don’t see you passing/setting anything.

    There’s no reason you can’t pass instances of clients to servers (and vice versa):

    Client myClient = new Client(args);
    Server myServer = new Server(args);
    
    BlueClient = myClient.getBlueClient();
    RedCLient = myClient.getRedClient();
    
    BlueServer = myServer.getBlueServer();
    RedServer = myServer.getRedServer();
    
    myClient.addServer(blueServer);
    myClient.addServer(redServer);
    
    myServer.addClient(blueClient);
    myServer.addClient(redClient);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, I apologize if this question has been asked before. I've done a
Ok. First let me apologize profusely if this question has been covered. I did
First off, I apologize if this has been asked before. I can't seem to
First off, let me apologize if this has been asked already, but I can’t
First, I apologize if this has been asked before - indeed I'm sure it
I apologize if this question has been asked before, but my case is a
First of I apologize if this is a dumb question - I'm just starting
First, let me apologize if this is the world's stupidest question. But, I'm stumped
First of all, apologize because I have seen some posts about this, but I
First, I apologize if this is not an appropriate venue to ask this question,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.