hi, i want to learn some core java design patterns .can anyone tell me what is singleton,how to write singleton, where exactly this fits in the application development pls explain in detail with example.
Most importantly: *don't* use it, unless you are very sure that there isn't a better design.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Typically, I wouldn't implement the singleton in the manner mentioned in the java ranch faq posted. Usually there is no reason for lazy initialization of the Singleton. Here is a thread on the sun java forum where I discuss an alternative approach to the singleton pattern.
I vote with Steve ... that's far and away the simplest and safest way to instantiate your singleton. And with Ilja ... we often think we need Singleton when we might not. They can have some negatives that you have to work to avoid. Do you want to describe your design a bit more and see if we all chime in with alternatives?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
posted 15 years ago
thank you all for your invaluable replies.
thanking you mohan dodderi
Seriously? That's what you're going with? I prefer this tiny ad: