In the quest for more opinions I rewrite the question (I´m learning how to ask and English is not my mother tongue)...
Is it redundant or best practice to keep all the methods and global vars as static? (I mean there´s only one instance already per se)
If none of the methods depend on the state (the instance attributes) of the class, then you don't need a singleton, simply declare them all as static - you'll have an utility class then (that's the second approach proposed in the question).
On the other hand, if the methods do depend on the state of the class, and you must ensure that only one instance of the class exists at any moment in time, then use a singleton (that's the first approach suggested in the question).
Notice that the second approach is not really considered a singleton, by definition a singleton is a pattern "used to implement the mathematical concept of a singleton, by restricting the instantiation of a class to one object", and a class with all-static methods doesn't need to be instantiated at all.
EDIT :
Regarding the invocation of static methods in a singleton class, it's considered bad style to invoke static methods on an object instance, it doesn't matter if it is a singleton or not. This has been discussed extensively in previous posts. So for consistency, I believe it'd be better to declare all the methods in a singleton as non-static, even if they don't depend on instance attributes, and access all of them through the singleton (the first approach in your question).
If a class makes use of any resources or is costly to initialize a singleton is usually worth the effort.
A singleton will give you much better control over the lifetime of the object. Static constructors are guaranteed to be called before any static methods are accessed however there is no way to force a static constructor to run again.
Singleton objects are easier to test, there is no way to have an interface over static methods.
A singleton can easily be converted to another implementation pattern, perhaps a pool of resources as opposed to a single object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With