View RSS Feed

Design Patterns

Protected constructor

Rate this Entry
by , 03-09-2012 at 07:49 PM (1123 Views)
For allowing the singletonís sub-classing, there is a possibility to use the protected constructor. Such technique consists of two main drawbacks which makes the inheritance of a singleton impractical.

  • If constructor is protected then instantiation of the class can be done by calling the constructor from some other class present in the similar package. Creation of the singletonís separate package can avoid it.
  • For using the derived class, change all getInstance calls present in existing code, from Singleton.getInstance() to NewSingleton.getInstance.

Number of singleton instances, if classes that are loaded by varying class-loader access one singleton.
If class gets loaded by two separate clasloaders it means two different classes are represented in memory.

Submit "Protected constructor" to Facebook Submit "Protected constructor" to Digg Submit "Protected constructor" to Submit "Protected constructor" to StumbleUpon Submit "Protected constructor" to Google