Difference between Static Class and Singleton class

This is my first blog and as a technical person I want to start with some technical stuff. So here is something technical I have choose, that is "Difference between Static Class and Singleton class".
Recently I went through with the Singleton class. Static class I already have gone through with, so I found many difference in between them. If you do the google many stuff you will be able to find on this topic but I tried to conclude them in short in my way. So let's begin with the actual differences:

  1. Singleton objects are stored in heap but Static objects stored in stack
  2. We can clone the Singleton object but we can not clone the Static object.
  3. We can implement interface with the Singleton class but we can not implement interface with the Static class.
  4. Singleton class allows all kind of methods and properties and other members whether it is public or private or internal or protected but Static class only accept static members.
  5. Static class can not have constructor other than static one.
  6. We can not pass Static class object to method as a parameter but we can do that with the Singleton class object.
  7. We can inherit other class to the Singleton class but same we can not do with the Static class.
  8. We can dispose the object of Singleton class but not the Static class because ideally we not creating the object of it.
  9. Singleton class method can be overridden (but here is twist because ideally Singleton class should be Sealed one and in that case it's members can not be a overridden) but Static class methods can not.
  10. Singleton can be lazy loaded when need where-as Static always loaded.
  11. Better performance static methods are bonded on compile time.
  12. Singleton members can be serialized which Static members can not.
  13. Static class care much easier to implement and Singleton is better if you have to pass object as parameter to any method.


Comments

Popular posts from this blog

Bhavu and Bahin

stri stuti

Lavani var kahi