I have a singleton class that manages the user state, let's say it's called UserStateManager. There are methods that I want to call like login and logout. However, it seems like I always have to do something like this:
UserStateManager.getInstance().login(user);
UserStateManager.getInstance().logout();
But I would like to instead do something like this:
UserStateManager.login(user);
UserStateManager.logout();
And have a static login and logout methods deal with obtaining the singleton instance. But at the same time I want to have instance methods still available in case I am doing multiple things with the singleton:
UserStateManager usm = UserStateManager.getInstance();
usm.login(user);
usm.setLocation(location);
usm.setVerified(true);
However Java doesn't allow static and instance methods to exist with the same signature. It does seem to allow you to call static methods from instances, but then I would have to call getInstance() even if I'm calling the method from an instance, which seems silly, but maybe that's the best option? What do people do in this situation? Just put up with it and call getInstance() all over the place?