HI,
In singleton class we are declaring constructors as private. Is it possible to give as protected.
If giving as protected is it beneficial.
Whats the advantage or disadvantage of private over protected
HI,
In singleton class we are declaring constructors as private. Is it possible to give as protected.
If giving as protected is it beneficial.
Whats the advantage or disadvantage of private over protected
If you make constructor private you can't make an object of that class from outside the class.If you make it as protected you can only use that constructor in subclasses of that class.
If you make the constructor protected, then any class inheriting from it could instantiate it multiple times. That would no longer make it a singleton.
Before you make a class into a singleton, thing hard if you really need to (do you really have to have a single instance of it in the whole application? Really?).
If you really want to have a singleton you have to avoid that "someone else" can create an instance of the class. That's why it should be private, and the class should be sealed, which makes protected just the same as private since there is no inheritance possible.