title: (Mis)usage of private constructor and static methods (Java)?
body: <p>I am currently working on a project that needs to be refactored (it was not written by me and the original developer is not around). I see in that application that rather many classes have only private constructors and one or more static methods (getter/setter of the current class object). They also have non-static methods. I give you one example:</p>
  
  <p>Class UndoManager that manages the actions taken on the application for performing undo/redo. It has only private constructors. When the application is loaded, UndoManager.setManager() is called. This method loads the undo history from a file or constructs a new one using a private constructor.</p>
  
  <p>Later, every class can access this instance of UndoManager with syngronized static method .getManager(). </p>
  
  <p>In code:</p>
  
  <pre><code>public class UndoManager extends SimpleObservable&lt;UndoManager&gt; {
  
      private static UndoManager instance;
      private final Stack&lt;Action&gt; undoHistory;
      private final Stack&lt;Action&gt; redoHistory;    
  
      public synchronized static void setManager(UndoManager undoManager) {
          UndoManager instance = getManager();
          instance.clear();
          instance.undoHistory.addAll(undoManager.undoHistory);
          instance.redoHistory.addAll(undoManager.redoHistory);
          instance.notifyObservers(instance);
      }
  
      public synchronized static UndoManager getManager() {
          if (instance == null)
              instance = new UndoManager();
          return instance;
      }
  
      private UndoManager() {
          this.undoHistory = new Stack&lt;Action&gt;();
          this.redoHistory = new Stack&lt;Action&gt;();
      }
      /.../
  }
  </code></pre>
  
  <p>In this application multiple classes are used like this. They are not helper classes but classes that should have only one instance.</p>
  
  <p>My question is:
  is this kind of access good style? If not, how would you refactor the class and it's access?</p>
  
  <p>I'm sorry if it is a duplicate, but I have searched in stackoverflow and google for a while but somehow I didn't find a satisfying answer. Thank you for any help.</p>