Singleton pattern: the purpose of empty constructor
So, as the topic says, I have noticed that people use empty constructor when implementing singleton pattern. I am wondering what is the difference between empty constructor and the default constructor, which is called if the class has no constructor at all?
Re: Singleton pattern: the purpose of empty constructor
If you are using the singleton pattern, you want to ensure that no one can create another instance of that class.
For this, you need to make sure that all your constructors are declared private. However, since you can only ever have one object, it makes no sense to provide "specialized constructors" other than an empty constructor because the values will always be initialized to the same default setting, so you might as well hard code them in.
You can't use the default constructor because it has public access, violating the Singleton Pattern.