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
← January 2022 →
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 | 31 |
My Blog Links
Recent Entries
-
-
-
SCJP Notes - Part 6on Mar 27 2008 08:19 AM
-
SCJP Notes - Part 5on Mar 27 2008 08:05 AM
-
Recent Comments
Search My Blog
13 user(s) viewing
13 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)



1 Comments









|