How can a singleton class use an interface?

AJ. picture AJ. · Sep 30, 2009 · Viewed 28.1k times · Source

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

Answer

nkr1pt picture nkr1pt · Sep 30, 2009

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.