How can a singleton class use an interface?

后端 未结 5 1885
盖世英雄少女心
盖世英雄少女心 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:38

    Every class can implement an interface, and a Singleton is just a "normal" class that makes sure that only one instance of it exists at any point in time apart from the other business logic it may implement. This also means that a Singleton has at least 2 responsibities and this is not good OO design as classes should only have 1 responsibility and make sure they are good at that responsibility, but that is another discussion.

提交回复
热议问题