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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:45:29+00:00 2026-06-12T12:45:29+00:00

Possible Duplicate: What is so bad about Singletons? Singleton Design Pattern: Pitfalls Singleton anti-pattern

  • 0

Possible Duplicate:
What is so bad about Singletons?

Singleton Design Pattern: Pitfalls

Singleton anti-pattern

I’ve heard recently that Singleton is an anti-pattern. I know it has to do with the fact making a class singleton is like making that unique instance a global variable, but it’s also doing a lot more than that (limiting the number of instances of that object, managing instantiation, etc..).

Why exactly is Singleton considered an anti-pattern? And what are the alternatives?

  • 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-12T12:45:30+00:00Added an answer on June 12, 2026 at 12:45 pm

    To help with answering, here is more about the anti-pattern comment:

    it is overused, introduces unnecessary restrictions in situations
    where a sole instance of a class is not actually required, and
    introduces global state into an application

    From: http://en.wikipedia.org/wiki/Singleton_pattern

    For more on this you can look at: https://www.michaelsafyan.com/tech/design/patterns/singleton

    Here is a great ending to the blog above:

    In short, the singleton pattern makes code more complex, less useful,
    and a real pain to re-use or test. Eliminating singletons can be
    tricky, but it’s a worthwhile endeavour.

    OK, so, the reason it is an anti-pattern is described well in this paragraph, and, as the author expresses, it tightly couples your code to the singleton.

    If you find that you want to use a singleton, you may want to consider your design, but there are times where it is useful.

    For example, once I had to write an application that could have at most one database connection, to process thousands of requests. So, a singleton makes sense since I am resource constrained to having only one instance.

    But, generally this is used to simplify code, without thinking of the difficulties that will be introduced.

    For example, and this applies to static classes also, if you unit test, or have concurrency, then the state of one request will change the state and that may cause problems, as the class calling the instance may be assuming the state is as it expected.

    I think the best way to challenge the use is to think of how to handle it if your program is multi-threaded, and a simple way to do that is to unit test it, if you have several tests that run at one time.

    If you find that you still need it, then use it, but realize the problems that will be encountered later.

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

Sidebar

Related Questions

Possible Duplicate: What is so bad about Singletons? Singleton Design Pattern: Pitfalls I hear
Possible Duplicate: What is so bad about Singletons? It's understandable that many design patterns
Possible Duplicate: What is so bad about singletons? Singleton pattern in C++ I want
Possible Duplicates: What is so bad about Singletons Problems with Singleton Pattern Are there
Possible Duplicate: What is so bad about singletons? I've read in several answers to
Possible Duplicate: Are iframes considered 'bad practice'? While working with web developers, I always
Possible Duplicate: Initialize class fields in constructor or at declaration? We are arguing about
Possible Duplicate: Why is it a bad practice to return generated HTML instead of
Possible Duplicate: What is the purpose of a marker interface? Is it bad practice
Possible Duplicate: PHP: Require() and Class Hierarchies Is this bad practice? Is there any

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.