Alex Rivera | Logout

Why implementing a Singleton pattern in Java code is (sometimes) considered an anti-pattern in Java world?

Asked 2012-07-02T10:45:34.057
37

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

Edit
Report

1 Answer

7

There are many requirements that you might have on the singleton:

  1. lazy initialization;
  2. proper disposal;
  3. scoping (one per thread, for example).

Typically, also, you'll have a whole lot of singletons in your app, and the Singleton pattern doesn't allow reusable code. So, if you want to implement all these concerns for all your singletons, you'll immediately see its anti-pattern quality.

answered 2012-07-02T10:54:35.047

Your Answer