4 ms·
Summary: singletons = global variables + static methods. Details: If you need some "utility function" whose output depends exclusively on its arguments, you w
by crpatino 16y ago
Summary: singletons = global variables + static methods.
Details:
If you need some "utility function" whose output depends exclusively on its arguments, you will be better of with an static method. However, this is a no fly for O-O-purists.
The option is to create a (possibly stateless) singleton class and put your non static method there. You will have the overhead of acquire the reference to the method in run time instead of compile time (and the few bytes needed to store the class and the ONE object reference).
On the other hand, singletons can be used to hold global state and the methods to legally change that global state. For this reason, they can be easily abused in order to bypass separation of concern rules and dress them in OOP-speak.