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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:19:47+00:00 2026-06-06T22:19:47+00:00

I have seen some people in SO commenting that Singleton Pattern is an anti-pattern.

  • 0

I have seen some people in SO commenting that Singleton Pattern is an anti-pattern. I want to know why ?

  • 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-06T22:19:48+00:00Added an answer on June 6, 2026 at 10:19 pm

    Testing

    One reason is that singletons aren’t easy to handle with unit tests. You can’t control the instantiation and by their very nature may retain state across invocations.

    For that reason the principle of dependency injection is popular. Each class is injected (configured) with the classes they need to function (rather than derive via singleton accessors) and so tests can control which dependent class instances to use (and provide mocks if required).

    Frameworks such as Spring will control the lifecycle of their objects and often create singletons, but these objects are injected into their dependent objects by the framework. Thus the codebase itself doesn’t treat the objects as singletons.

    e.g. rather than this (for example)

    public class Portfolio {
       private Calculator calc = Calculator.getCalculator();
    }
    

    you would inject the calculator:

    public class Portfolio {
       public Portfolio(Calculator c) {
          this.calc = c;
       }
    }
    

    Thus the Portfolio object doesn’t know/care about how many instances of the Calculator exist. Tests can inject a dummy Calculator that make testing easy.

    Concurrency

    By limiting yourself to one instance of an object, the options for threading are limited. Access to the singleton object may have to be guarded (e.g. via synchronisation). If you can maintain multiple instances of those objects, then you can tailor then number of instances to the threads you have running, and increase the concurrent capabilities of your codebase.

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

Sidebar

Related Questions

I've seen some people that have managed to use the themes in the Silverlight
I have seen some instances where people will say you have to use JS
I have seen people writing $(document).ready(function(){ }); and some writing $(function() { }); What's
I have seen prefix N in some insert T-SQL queries. Many people have used
I have seen some examples of the random int in Objective-C, but all people
I have seen some examples of people using avifil32.dll to read / write AVI
i have seen some code in which people pass parameter through commandParameter Property of
Some people have suggested that when doing an estimate one should make a lower
I have seen some people regard extending the natives prototypes in Javascript with disdain.
I have seen the trend that many people don't like to use exceptions in

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.