Hi..Java Programmers..!
Can You please tell the use of Singletons in Programming,
And how this would be useful in Applications.
Thanks in Adavance,
Sivanand
-
What is the use of Sigleton Classes (1 messages)
- Posted by: Sivananda Hanumanthu
- Posted on: March 25 2006 06:29 EST
Threaded Messages (1)
- What is the use of Sigleton Classes by umar ali on March 26 2006 20:11 EST
-
What is the use of Sigleton Classes[ Go to top ]
- Posted by: umar ali
- Posted on: March 26 2006 20:11 EST
- in response to Sivananda Hanumanthu
using singleton pattern, only a single instance of a class exists which can be used by others. It does not allow creation of new objects of the same class on the heap.
An exaple
public class Singleton{
private Singleton(){
}
private static Singleton cInstance;
public static Singleton getInstance(){
/** only create an instance if there is none*/
if(cInstance == null){
cInstance = new cInstance();
}
return cInstance;
}
public void yourMethod(){
}
}