Why is it mandatory to have private Constructor inside a Singleton class

前端 未结 10 1124
心在旅途
心在旅途 2020-12-10 08:12

This is my singleton class for obtaining the database connection.

I have a question here: why it compulsory to have a private constructor inside a singleton class (a

10条回答
  •  暖寄归人
    2020-12-10 08:58

    For the singleton pattern you use an private constructor to ensure that no other instances can be created, otherwise it wouldn't be a singleton.

提交回复
热议问题