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

The Archive Base Latest Questions

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

Not quite sure whether this has been asked before. Language is c++. I am

  • 0

Not quite sure whether this has been asked before.

Language is c++. I am writing a class with a number of data items that should have a static behavior, say a buffer of 1 KB that holds some data and should be shared for all objects. My boss ask me, why don’t you write a singleton class and put all the data items inside it?

I have some bitter experiences with singleton and also recently I have googled “singleton is evil” and read a couple of articles. In SO also I read the same. So I was a little hesitant to use singleton in the above case, because I believe it is not really required there. So I asked my boss, will it be OK to have static data members for the required data items, instead of making the class singleton? But he is not giving me any clear answer and tells me, design patterns are there to make life easier, so what is the problem in using it. I don’t want to argue with him. 🙂

I am not an OOP expert. So it will be helpful if somebody can comment on whose point make more sense [also whether both are wrong :)].

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-06-18T02:59:16+00:00Added an answer on June 18, 2026 at 2:59 am

    A singleton is essentially nothing but some OO encapsulation around a global variable.

    If you encapsulate your state in some class and just add that as a static member to the class that needs the info, you’re not really doing much different from a singleton, just with at least two drawbacks:

    • You preclude sharing that state with other classes.
    • In the simple implementation, there’s nothing to stop anyone from creating another instance of your new class. If that is semantically an invalid thing, you should not allow it in the code, and that means you have to write all that singleton functionality anyway.

    Sure, Just slapping a bit of Singleton Magic on top of globals doesn’t make the problems with global state go away, and in that sense, singletons are evil™. But there are cases where your model needs to have global state. Encapsulation is a good thing in those instances, since it allows you to control who modifies what, when, and how. You can make the singleton factory method only accessible to certain classes, for example.

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

Sidebar

Related Questions

Not quite sure how to word this question. I am wondering if there is
I'm not quite sure the best way to deal with this situation. Here's a
I'm not quite sure how to go about styling this particular bit of php:
I'm not quite sure how to approach this issue: I am creating a web
I'm not quite sure how to do this. Let's say I have 2 associative
This has been on my mind for quite some time and I figured I
I'm not sure whether this belongs on StackOverflow or on ServerFault, so I've picked
I'm not quite sure what I need to be asking to solve this problem,
Not quite sure how to go about describing what it is I'm trying to
Im not quite sure what I am doing wrong here, I have folloed the

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.