Where and How you can use private Constructor?
>> Monday, May 30, 2011
Private constructor is used if you do not want other classes to instantiate the object and to prevent subclassing.
The instantiation is done by a public static method within the same class.
Used in the singleton design pattern. Used in the factory method design pattern e.g. java.util.Collections class .
Used in utility classes e.g. StringUtils etc.
The instantiation is done by a public static method within the same class.
Used in the singleton design pattern. Used in the factory method design pattern e.g. java.util.Collections class .
Used in utility classes e.g. StringUtils etc.
0 comments:
Post a Comment