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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:17:43+00:00 2026-05-20T12:17:43+00:00

I have about 15~20 member variables which needs to be accessed, I was wondering

  • 0

I have about 15~20 member variables which needs to be accessed, I was wondering
if it would be good just to let them be public instead of giving every one of them
get/set functions.

The code would be something like

class A { // a singleton class
public:
    static A* get();

    B x, y, z;
    // ... a lot of other object that should only have one copy
    // and doesn't change often

private:
    A();
    virtual ~A();
    static A* a;
};

I have also thought about putting the variables into an array, but I don’t
know the best way to do a lookup table, would it be better to put them in an array?

EDIT:

Is there a better way than Singleton class to put them in a collection

  • 1 1 Answer
  • 1 View
  • 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-05-20T12:17:44+00:00Added an answer on May 20, 2026 at 12:17 pm

    The C++ world isn’t quite as hung up on “everything must be hidden behind accessors/mutators/whatever-they-decide-to-call-them-todays” as some OO-supporting languages.

    With that said, it’s a bit hard to say what the best approach is, given your limited description.

    If your class is simply a ‘bag of data’ for some other process, than using a struct instead of a class (the only difference is that all members default to public) can be appropriate.

    If the class actually does something, however, you might find it more appropriate to group your get/set routines together by function/aspect or interface.

    As I mentioned, it’s a bit hard to tell without more information.

    EDIT: Singleton classes are not smelly code in and of themselves, but you do need to be a bit careful with them. If a singleton is taking care of preference data or something similar, it only makes sense to make individual accessors for each data element.

    If, on the other hand, you’re storing generic input data in a singleton, it might be time to rethink the design.

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

Sidebar

Related Questions

I have a class with several member variables, one of which is a DefaultTableModel.
I have a question about how to access the member with the same name
I have the model Member that contains all informations about the registered member on
I have a C struct with about 17 members struct settings currentProfile and would
I have about 50 RadioButtonList on a form with a checkbox next to them.
I have about 10 drop down list controls that get populated. Instead of copying/pasting
I have created an abstract base class Animal which has public virtual abstract method
Imagine you have a class with dozens of private member variables. Each member variable
Let me just say up front that what I'm aware that what I'm about
I have a public method which uses a variable (only in the scope of

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.