You've got two questions: when should I call a getInstance()
method, and when should I create one?
If you're deciding whether to call a getInstance()
method, it's easy. You just need to read the class documentation to find out when you should call it. For example, NumberFormat
provides a constructor and a getInstance()
method; the getInstance()
method will give you a localized NumberFormat
. For Calendar
, on the other hand, the constructor is protected. You have to call getInstance()
to get one.
If you're deciding whether to create a getInstance()
method, you need to decide what you're trying to accomplish. Either you don't want people to call your constructor (you're creating a singleton or a factory), or you don't mind (as in NumberFormat
above, where they're initializing some objects for the convenience of the caller).
Long story short? Don't worry about creating getInstance()
methods in your own code. If the time arises when they'll be useful, you'll know. And in general, if you can call a class's constructor, you're probably supposed to be doing that, even if the class provides a getInstance()
method.