Friday, January 15, 2016

Singleton Class vs Static Class

Singleton Class

Static Class

·         They can be extended
·         Cannot
·         They can be passed around as an object
·         Cannot
·         They can Garbage collected
·         Cannot
·         They can override methods defined in Singleton class by extending it.
·         Cannot as it leads to inflexibility
·         Easy to create mock object for JUnits
·         Difficult to create mock objects and hard to test
·         They can be LAZY loaded if it’s a heavy object
·         Always early loaded
·          
·         Better performance as static methods  are bonded at compile time
·         Use when need full  OO capability i.e. inheritance and polymorphism
·         Use when need to store bunch of static methods together