How to implement Singleton

Answer Posted / supraja

The Singleton pattern
In Design Patterns, the authors describe the Singleton
pattern like this:

Ensure a class has only one instance, and provide a global
point of access to it.



The figure below illustrates the Singleton design pattern
class diagram.



Singleton class diagram

As you can see from the figure above, there's not a whole
lot to the Singleton design pattern. Singletons maintain a
static reference to the sole singleton instance and return
a reference to that instance from a static instance()
method.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which is better stringbuilder or stringbuffer?

719


Can we declare register variable as global?

738


What is integers and example?

710


Which is dependent variable?

677


Explain about anonymous inner classes in java?

797


Can we instantiate interface in java?

908


Explain the importance of finally block in java?

752


What language is an assembler written in?

767


How do you implement singleton class?

756


How we can make copy of a java object?

872


What is a boolean flag in java?

778


Does anyone still use java?

851


Why singleton pattern is better than creating singleton class with static instance?

800


Are floats faster than doubles?

788


Similarity and difference between static block and static method ?

731