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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:11:25+00:00 2026-05-19T10:11:25+00:00

Recently, I refactor code of my project, I found there are lots of singleton

  • 0

Recently, I refactor code of my project, I found there are lots of singleton object, almost one function one singleton.

For example, I should do period task, so I have a class called CPeriodTask, and have a thread function called ScanPeriodTaskThreadProc and a member variable which save tasks, and CPeriodTask is a singleton object.

There are so many singleton object in my project, and a few of singleton object refer to
other singleton object.

Now I want to reduce use of singleton and break reference of singleton.
Any Suggestions, Thanks.

  • 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-05-19T10:11:26+00:00Added an answer on May 19, 2026 at 10:11 am

    One way to reduce singletons is to create some god-class, a SingletonManager, which can then contain all of the other singletons as instance members. That is, you remove the singleton behavior of the existing singletons in your projects, and this manager then creates/destroys these objects as desired, in the correct order, since you mentioned some of these objects have dependencies on each other.

    So at the top of main, you create the SingletonManager, publish some reference to this object so the rest of your code can get at these former-singleton objects. And, just as important, at the bottom of main, you “shutdown” the manager which itself then deterministically destroys these objects in the correct order. Again, this is important because you mentioned inter-dependencies between these objects, and at least one singleton you have now involves a thread.

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

Sidebar

Related Questions

Recently downloaded some code for a minor open-source project related to a small webgame
Recently I found some simple source code of a bootloader.The following is the simple
I'm refactoring some code that a friend wrote and recently stumbled across this function:
Trying to refactor some code that has gotten really slow recently and I came
Recently I've spotted a very disturbing issue. I've got the following python code: for
Recently I just got assigned a project to develop a web application/site that uses
Recently I have been learning about WMI and WQL. I found out the list
Recently I came across a recommendation for a Visual Studio plugin called Refactor! For
I recently read Michael C. Feathers' book Working effectively with legacy code and came
I've recently implemented a couple of similar-sized web applications, one of which used a

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.