The Singleton pattern is used for classes which should have only one instance in the application. The other classes can't invoke the constructor directly because it is declared private and some public static method is provided which returns the single instance. This pattern makes the instance available globaly and thus should be used carefully.
e.g.
e.g.
class InstanceOne{
InstanceOne one;
private InstanceOne(){}
public static InstanceOne getInstance(){
if(one != null) {
return one;
} else {
one = new InstanceOne();
}
}
}
1 Comments On This Entry
Page 1 of 1
amitbhandari
28 February 2008 - 11:48 PM
I guess, you are missing description of thread-safe singleton pattern here wherein the execution block of constructor should be made critical until either the new object has been created or the old object has been returned.
Page 1 of 1
My Blog Links
Recent Entries
Recent Comments
Search My Blog
1 user(s) viewing
1 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)
|
|



1 Comments









|