This blog has moved to http://ikhwanhayat.net

Saturday, January 14, 2006

Singleton Considered Stupid

Singleton is stupid? Eheem.. I do wonder sometimes on why don't I use a static method instead of a singleton. The article said "functional programming" in some part. I do heard it a lot about it. Maybe I ought to try some Haskell one day.

3 Comments:

At 1/17/2006 12:37:00 pm, Blogger Hamdi said...

Use Singleton the concept, instead of Singleton the implementation (as in the GoF) book. For me, in Java, I implement my Singletons using static methods too (or using IoC). They are still Singletons, just different implementations.

As for having multiple implementation, you can actually have that with a Singleton. I can implement a Java Singleton that behave differently. Sort of a combination of Singleton plus Strategy with a good dose of delegation.

Just MHO. :)

 
At 1/17/2006 07:09:00 pm, Blogger Ikhwan Hayat said...

Ahah, the concept.. Not the implementation.. Now I understand.
Actually the patterns are all about concept aren't they? Implementations may vary right?

Thanks a lot bro hamdi.. :)

 
At 1/17/2006 08:49:00 pm, Blogger Foobaz said...

From book Refactoring to Patterns:

If you use the Singleton pattern out of habit, because it "makes your code more efficient", you're premature optimizing

premature optimized code = harder to refactor

 

Post a Comment

<< Home