small artical on Singleton

Hi Team,

I have added an small artcal on "Singleton pattern" at

http://javatouch.googlepages.com/singletonpattern

I have used some of wisdom from contents of this forum in creating the artical. Please feel free to visit the link and do not hesitate to comment or note any thing missing or incorrect there.

Regards,

Nalaka

http://javatouch.googlepages.com/

[398 byte] By [javatoucha] at [2007-10-3 8:28:14]
# 1

What is this supposed to mean?

Note the distinction between a simple static instance of a class and a singleton. Although a singleton can be implemented as a static instance, it can also be lazily constructed,...

A Singleton is a class for which only one instance exists. The way you do it in Java is by providing a reference to that instance as a static member variable. This is true whether you lazyily instantiate or not. "Static instance," doesn't really mean anything

Also, rather than saying, "not guaranteed to work," you should say that the DCL presented there does not work. Since DCL's job is to guarantee that only one instance is created and that it's not used before construction is complete, and since it can't make that guarantee, it does not work.

It's true that with the new JMM introduced in 5.0 you can make DCL work if the member variable is declared volatile, but there's no reason to do it--that idiom is more complex than others and doesn't give you anything not available through other means.

jverda at 2007-7-15 3:34:56 > top of Java-index,Other Topics,Patterns & OO Design...