Possible Duplicate:
Efficient way to implement singleton pattern in Java
I have a singleton class that acts as a state saver for my application. For instance if I have a view that has some data, I just pacakge the data to a saved state serializable object and pass it to my singleton for retrival later. This all seems natural and proper, but I have deviated from the singleton example on Wiki. Intead of having a get instance method that will let me retrieve the instance and call methods though the instance, I instead just set every method to static and use the class statically.
Is this bad form? Is there a performance lose?
Thanks for any tips ~Aedon
If static use fulfills your needs, I don’t see any evil in it.
The only downside is that it’s slightly less flexible. If you designed it as an actual singleton, you could have an interface for managing state, and instantiate a particular implementation for a specific situation. This object could then be passed into your application as an argument.
Using a strictly static class, there’s not object to pass, so you’d have to resort to passing around Class objects and accessing the functions through that interface.
Of course, all of that only matters if there’s any chance this would ever expand beyond the reasonable capabilities of your current class.