Delete comment from: Javarevisited
I would agree with Anand in that most definitions consider extending a Singleton as breaking the definition... Likewise for cloning and serialization...
Also, since one can use/pass around between threads the Singleton instance, any mutable state it might have makes the object susceptible to race conditions as well...
The fact that "a Singleton follows the OOP principles" is utterly irrelevant since in order to really implement the pattern we have to renounce most of the OOP principles and flexibility anyway...
Moreover, having static classes/methods means less parameters to a method that needs this (static or singleton) functionality, eventually less injection, etc. so basically reduced "interfaces" which is normally good. However, this "lack of dependencies" might tend to hide things, introduce magic behavior and inflexible design. Hence, we get to the only situation and strong point (that Saral made and) that could favor a Singleton: implementing an interface and being passed around as just one of the possible implementations...
Mar 16, 2013, 10:15:26 AM
Posted to Difference between Singleton Pattern vs Static Class in Java? Example