Should I create protected constructor for my singleton classes?

Posted by Vijay Shanker on Stack Overflow See other posts from Stack Overflow or by Vijay Shanker
Published on 2010-12-08T00:49:28Z Indexed on 2013/11/06 9:54 UTC
Read the original article Hit count: 200

Filed under:
|
|

By design, in Singleton pattern the constructor should be marked private and provide a creational method retuning the private static member of the same type instance. I have created my singleton classes like this only.

public class SingletonPattern {// singleton class

    private static SingletonPattern pattern = new SingletonPattern();

    private SingletonPattern() {

    }

    public static SingletonPattern getInstance() {
        return pattern;
    }

}

Now, I have got to extend a singleton class to add new behaviors. But the private constructor is not letting be define the child class. I was thinking to change the default constructor to protected constructor for the singleton base class.

What can be problems, if I define my constructors to be protected?

Looking for expert views....

© Stack Overflow or respective owner

Related posts about java

Related posts about design-patterns