Link Details

Link 33115 thumbnail
User 160542 avatar

By kirillcool
via dailydevelopment.blogspot.com
Published: Aug 02 2007 / 03:43

There are a lot of posts about that the Singleton design pattern is not pattern but anti-pattern. Some posts also propose alternatives for Singleton design pattern or solutions for already existing Singleton design pattern problem. But I haven't found any post which describes solution for big project with bunch of singleton class usage without big effort of rewriting many places by hand.
  • 18
  • 3
  • 5337
  • 3046

Comments

Add your comment
User 235974 avatar

warpedjavaguy replied ago:

1 votes Vote down Vote up Reply

The motive is good :)

User 162372 avatar

wolfdancer replied ago:

1 votes Vote down Vote up Reply

finally a post talks about what should be talked about regarding singlton

User 209464 avatar

willcode4beer replied ago:

1 votes Vote down Vote up Reply

Wasn't one of the "features" of the singleton design pattern that you can replace:
public static MyBigObject getInstance() {
return INSTANCE;
}
with:
public static MyBigObject getInstance() {
return new MyBigObject();
}
to change away from the singleton (without changing any other code).
I guess that's really the factory pattern part of a singleton.
Maybe the anti-singleton rhetoric is really pro-factory
;-)

User 161628 avatar

spand replied ago:

0 votes Vote down Vote up Reply

I dont know about other people but I used (and saw it as a feature of singletons) == for equality on singletons quite a lot for some time. So if some people are like me, which I am quite sure there are, then it wont be just that easy. Maybe this is one of the reasons its considered an antipattern..

User 79499 avatar

in86835 replied ago:

0 votes Vote down Vote up Reply

So naive, the bloke has no real clue why Singletons exist or how to use them properly, his 'solution' looks a lot worse than a Singleton, especially for multi-threaded code.

willcode4beer:
No factories are not the same as Singletons. Factories can have an interface and different implementations or instances. and only provide objects which are instances of a class or interface. Singletons have at most one instance per context and can receive or return primitive or object values, they can act like factories, but not all factories are Singletons..

Enum objects are Singletons too!

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.