What are the differences between a Static class and a Singleton?

  • singleton class can be instantiated only once, static class can't be instantiated.
  • singleton class can inherit an interface, resulting in creating many implementations in runtime if needed, static classes can't do implement interface.
  • singleton class can be injected in constructors, static classes can't.
  • with singletons, we can know exactly when the class is instantiated, with static class we don't have the control over the object.
  • static classes are sticky; they create a coupling when used inside a class.
  • static classes can't be changed, if we need to change some value inside a static class we need to restart the server.
  • singleton class can be instantiated only once, static class can’t be instantiated.
  • singleton class can inherit an interface, resulting in creating many implementations in runtime if needed, static classes can’t do implement interface.
  • singleton class can be injected in constructors, static classes can’t.
  • with singletons, we can know exactly when the class is instantiated, with static class we don’t have the control over the object.
  • static classes are sticky; they create a coupling when used inside a class.
  • static classes can’t be changed, if we need to change some value inside a static class we need to restart the server.
Default image
Sriram Mannava

I'm a full-stack developer and a software enthusiast who likes to play around with cloud and tech stack out of curiosity.

Leave a Reply