How can a singleton class use an interface?

后端 未结 5 1987
盖世英雄少女心
盖世英雄少女心 2021-02-04 11:09

I read at many places that singletons can use interfaces. Some how I am unable to comprehend this.

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-04 11:39

    Basically, a singleton class is a class which can be instantiated one and only once. The singleton class pattern is implemented by using a static method to get the instance of the singleton class and restricting access to its constructor(s).

    As with the usage of an interface, it would be similar to the way any other class would implement an interface.

    And also it shouldnt allow cloning of that object.

提交回复
热议问题