I found this explanatory link which states
Ensure a class has one instance, and provide a global point of access to it.
I recently appeared at an interview and to my surprise it was asked from me too that can singleton class have multiples instances, my technology being Java and Objective C. My answer to this question was NO which I believe is right as Singleton variable being global shall check if it is null
or not. And it will be null
only the first time.
However out of curiosity I was confirming it. Can someone provide a confirmation with explanation weather I am right or wrong.
The word Singleton by definition(of Design Patterns) does not allows multiple instances, but yeah you can tweak the class to create multiple instances but then it won't be considered as a Singleton by definition
Well-designed singleton can have only one instance per application. Creating of multiple instances is a mistake in the application design. It might happen in some cases, e.g.:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With