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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:24:42+00:00 2026-06-03T20:24:42+00:00

I have a singleton class for the settings of the software. In different places

  • 0

I have a singleton class for the settings of the software. In different places in the large software it is possible to getInstance and use it to access settings which are already read into the settings class from a file. However:

  • In initial call it is necessary to pass a “model name” (the software loads and runs simulation models) and based on the name, the software will load settings of the selected model.

    Settings::getInstance(“building1”)

  • In later calls, it is not desired (or sometimes possible) to pass “model name” again. So it will be ideal if we can call without the model name.

What should I do in this scenario? Have 2 getInstance methods? Or set the “model name” to an static variable in Settings class before making the first call to getInstance? Or what?

  • 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-03T20:24:44+00:00Added an answer on June 3, 2026 at 8:24 pm

    Having 2 getInstance() methods sounds like a recipe for disaster 🙂 I would imagine the users of the class would always be asking: “Well which one do I use?” What would happen if someone called the wrong version first?

    Instead of using 2 getInstance() methods, I think it would be better to use the static variable approach, and set it early in the initialization phase. But this is also error-prone.

    Even better would be to consider some sort of a factory that takes the model name upon instantiation and has a singleton internally. The factory could be something like this:

    class SettingsFactory
    {
    public:
        SettingsFactory(const std::string &modelName);
        Settings *getUniqueSettingsInstance();
    
    private:
        SettingsFactory(); // cant instantiate the default ctor
    
        // put the singleton stuff here
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a singleton class for global access to config information. This singleton class
I have a singleton class which is being used throughout the app. I am
I have a java singleton class that has my application settings. I used this
I have a class which reads some settings from an XML file with simplexml.
I have a Singleton class which is highly dependent on the XML file it
I have a Singleton Class SharedDataObject which has a another class object myClass. MyClass
I have a singleton class which I would like to be created using Spring's
Let's say I have a singleton class like this: class Settings include Singleton def
I have a singleton class which needs to be intialized by castle? I'm a
I have a singleton class which manages data and database handling of my application.

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.