Not quite. Making it final would make it safer in cases where other people are going to use your class and which may try to subclass it. Still, i would make it final just in case, but the trick is to have only one private no-arg constructor. Have a static method which checks the static reference to the object (itself) to see if it has been instatiated already or not. Make sure you handle thread-safety issues (ie. you might want to synchronize the static method), and watch out for clients which try to clone the singleton (you can implement your own clone() method in the singleton class which simply throws and exception when called).
GoF goes on at length about subclassing and ways to choose which concrete class to use. If the private constructor prevents extension in Java, that's a problem with the implementation, not a rule of the pattern.
GoF says the class must be written so that only one instance can be created. If we fudge that rule and move the responsibility for singleness to a factory or registry we can lose the private constructor.
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
The fact that we put in a private constructor means that it cannot be subclasses, but by declaring it as final, we make our intention more explicit and allows the compiler to apply performance optimizations.
SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD, SCEA/OCMJEA
Live life to an interface, not an implementation!
posted 13 years ago
Design Pattern is a rule. As per the singletone pattern rule, we have to allow only instance in a JVM for a Class.
We can design anyway, but we have to mind the Singletone Pattern rule.
So private constructor is a one way to design singletone pattern.
According to Stan James, i understand that we can design singlepattern in some other way like factory, registry or anyway with allowing one instance per class.
So my conclusion is Singletone pattern need not be a Final Class.