Java: Best practices for turning foreign horror-code into clean API...?

Posted by java.is.for.desktop on Stack Overflow See other posts from Stack Overflow or by java.is.for.desktop
Published on 2010-03-21T20:57:13Z Indexed on 2010/03/21 21:01 UTC
Read the original article Hit count: 303

Hello, everyone!

I have a project (related to graph algorithms). It is written by someone else.

The code is horrible:

  • public fields, no getters/setters
  • huge methods, all public
  • some classes have over 20 fields
  • some classes have over 5 constructors (which are also huge)
  • some of those constructors just left many fields null
    (so I can't make some fields final, because then every second constructor signals errors)
  • methods and classes rely on each other in both directions

I have to rewrite this into a clean and understandable API.

Problem is: I myself don't understand anything in this code.

Please give me hints on analyzing and understanding such code.

I was thinking, perhaps, there are tools which perform static code analysis and give me call graphs and things like this.

© Stack Overflow or respective owner

Related posts about api

Related posts about refactoring