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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:18:40+00:00 2026-06-11T02:18:40+00:00

Is it good programming practise, when dealing with multiple classes that need the same

  • 0

Is it good programming practise, when dealing with multiple classes that need the same instance of variables, to create one central one?

chatWindow.variables.username = userField.getText();

For example:

  1. I have a class with a set amount of variables
  2. I have another class that needs the same variables
  3. And another that needs the same variables as the first

So I have three classes that all use the same instance of variables

I only create the variable class instance using the first class (1)

I access these variables using classes (2), (3) through the class (1)

Example:
(while in classTwo()):

classOne.variableClass.VariableName = false;

EDIT: In basic form, my question is if it is OK to make a central ‘variable class’ and use other classes to access the same isntance of it through a main class.

I know my question is hard to understand but Im sure there is another, easier way. I tried passing the same instance of the first class through the constructor of the second and third classes but my solution some how seemed simpler.

  • 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-11T02:18:42+00:00Added an answer on June 11, 2026 at 2:18 am

    This smells like feature envy… Sounds like something’s wrong with your model when doing that.

    If there’s a group of variables that need to be changed in multiple classes, it probably should become an object (probably even an entity). But you should consider that if you need to change these values in other classes, you might need to put some logic in that same class (to do validation checks and such).

    Having an extra class just to keep variables is usually considered a code smell, called anemic domain. However there are cases that do call for it, and it might be a matter of taste anyway. In that case, your class is nothing but a glorified struct.

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

Sidebar

Related Questions

I've read that good programming practice claims that one should use a function if
I have been told that Eclipse is a good tool for programming in certain
Please let me know which of the following is a good programming practise: 1.
What do you think about this programming practice: - I need to execute one
Just wondering if the following is considered to be good programming practice or not?
This question is about good programming practices and avoiding potential holes. I read Joshua
Does anybody know of a good resource for programming the behaviors of various materials
What is good book for industry level C++ programming? I am not looking for
I'm looking for a good easy to use Java based Quadratic Programming (QP) solver.
Thanks to Jeremy Miller's good work in Functional Programming For Everyday .NET Development ,

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.