What is the purpose of getInstance()
in Java?
During my research I keep reading that getInstance()
helps achieve a Singleton design pattern (which means just one instance across the whole program to my understanding). But can't I just use static? Isn't that the whole point of static?
If I were to just have static methods and fields, how would it differ from using getInstance()
? Is there a "scope" of static? For example, one instance per method or class?
And if they are different, in what cases would I choose getInstance()
over using static?
I apologize if the question is unclear, I am sure I am missing something on the subject matter, I just can't figure out what.
Thank you for any and all advice.