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 9117279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:52:01+00:00 2026-06-17T04:52:01+00:00

I am working on a projects and I have run into a problem, I

  • 0

I am working on a projects and I have run into a problem, I don’t know the best way to share updated data between classes. The current way that I am doing this is by having a static instance of my class in it and having all the other classes change the instance and not the original class.

public class A{
  public static volatile instance;
  public B b = new B();
  public C c = new C();
  public D d = new D();
  public A(){
  this.instance = this;
  b.changeData();
  }
}

public class B{
  public void changeData(){
  A.instance.d.changeSomethingInD();
  }
}

Now, all the changes that D made to its variables can be accessed by B and C. Is there a better way to do this?

Edit 1: The problem that I have is having updated variables accessible to all the other classes. This was what I was doing before:

public class MainClass extends JavaPlugin{
  private RegionLoader rLoader;
  private ClassesLoader cLoader;
  private MessageHandler mHandler;
  private PlayerDates pDates;

  public MainClass(){

      dirMaker();

      mHandler = new MessageHandler(this);
      pDates = new PlayerDates(this);
      cLoader = new ClassesLoader(this);
      rLoader = new RegionLoader(this);

  }
//getters and setters
}

But the problem is if the RegionLoader changes somithing within itself, the ClassesLoader won’t have the updated variables and will work with the old ones, or would it?

  • 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-17T04:52:02+00:00Added an answer on June 17, 2026 at 4:52 am

    Why not just pass A into the constructor of B. This way you wouldn’t need to use static data.

       public class A{
    
          public B b;
          public C c = new C();
          public D d = new D();
    
          public A(){
             b = new B(this);
             b.changeData();
          }
        }
    
        public class B{
          private A a;
    
          public B(A a){
             this.a = a;
          }
          public void changeData(){
             a.d.changeSomethingInD();
          }
        }
    

    You could also checkout the observer pattern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working on a console application using Delphi 7, and have run into a problem.
I have been working on this yahtzee project and have run into a problem.
I'm working on an iOS project with storyboards and have run into a problem
I'm working on a small project and I've run into a small problem. The
I am working on a project for work and have seemed to run into
I've been using SVN to track my projects, and I've run into a problem
On the project that I'm currently working I have a requirement to run a
I have been working through projects involving packages that do all the web design
We have started working on VS11 projects involving a DDD - Agile - TDD
I'm working on a build script with Gradle. We have multiple projects at our

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.