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

  • Home
  • SEARCH
  • 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 110961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:18:34+00:00 2026-05-11T02:18:34+00:00

I was confused when I first started to see anti-singleton commentary. I have used

  • 0

I was confused when I first started to see anti-singleton commentary. I have used the singleton pattern in some recent projects, and it was working out beautifully. So much so, in fact, that I have used it many, many times.

Now, after running into some problems, reading this SO question, and especially this blog post, I understand the evil that I have brought into the world.

So: How do I go about removing singletons from existing code?

For example:
In a retail store management program, I used the MVC pattern. My Model objects describe the store, the user interface is the View, and I have a set of Controllers that act as liason between the two. Great. Except that I made the Store into a singleton (since the application only ever manages one store at a time), and I also made most of my Controller classes into singletons (one mainWindow, one menuBar, one productEditor…). Now, most of my Controller classes get access the other singletons like this:

Store managedStore = Store::getInstance(); managedStore.doSomething(); managedStore.doSomethingElse(); //etc. 

Should I instead:

  1. Create one instance of each object and pass references to every object that needs access to them?
  2. Use globals?
  3. Something else?

Globals would still be bad, but at least they wouldn’t be pretending.

I see #1 quickly leading to horribly inflated constructor calls:

someVar = SomeControllerClass(managedStore, menuBar, editor, sasquatch, ...) 

Has anyone else been through this yet? What is the OO way to give many individual classes acces to a common variable without it being a global or a singleton?

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

    Dependency Injection is your friend.

    Take a look at these posts on the excellent Google Testing Blog:

    • Singletons are pathologic liars (but you probably already understand this if you are asking this question)
    • A talk on Dependency Injection
    • Guide to Writing Testable Code

    Hopefully someone has made a DI framework/container for the C++ world? Looks like Google has released a C++ Testing Framework and a C++ Mocking Framework, which might help you out.

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

Sidebar

Related Questions

I started reading 'Introduction to Algorithms' today, but I've gotten a bit confused over
I'm currently building my first Mac application and I'm a little confused by the
Hi I'm building my first MVC 2 app and I'm really confused by all
Why are the British confused about us calling bread rolls “biscuits” when they call bread rolls “puddings”?
I am a bit confused about socket programming in C. You create a socket,
I am bit confused about ADO.Net Data Services. Is it just meant for creating
I'm a bit confused here. Microsoft as far as I can tell claims that
I am confused between the term file modification time and file changed time. Can
I'm a little confused about how the standard library will behave now that Python
I'm confused with how views are organized, and it is important to understand this

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.