Home Development Blog Code Refactoring
Code Refactoring PDF Print E-mail
User Rating: / 0
Tuesday, 12 October 2010 08:51

Just before going into Sprint 3, I had a thought that perhaps now would be a good time for some housekeeping of the source code.   Known as refactoring in software circles.

The code for refactoring splits up into:

  1. The Solver interface GWT code.
  2. The Submission Interface GWT code.
  3. The Database structure.
  4. The Database access code, server side.
  5. The RPC interface.

First step in this digital age (as every computer specialist knows) is to print out some paper versions of the code and start scribbling on it...   So that's what I did.

One thing that the books recommend as a prerequisite for refactoring is that one has a solid set of automated tests that can be rerun after each incremental change to verify that the behaviour has not been broken.   I have too many different interfaces in this project (that was partly the point of the project) and the project is too small in scale for me to be able to afford that.   And there aren't enough tools to support appropriate testing other than at the java call level (Junit) which wouldn't prove very much in case of the user interface.   I could probably usefully use JUnit for the back end though, and I may yet do so at some stage in the project.

Refactoring the front end, the main thing that I decided to change was to separate out the RPC code from the user interface, especially the handling of error messages and retries.   So that meant writing a generic class that could be instantiated for each concrete RPC dialog.   With some callbacks to actually allow the user provide some payload.   all good healthy clean fun and it works fine.   It also meant changing the RPC interface so that all responses are objects which implement a common interface - mainly to allow comments to be returned from the server on what went wrong.   During the course of this I learned that the GWT RPC mechanism does not handle classes and sub-classes well...   So, everything was done with interfaces and reimplementing the necessary code in each class.

I also moved the select a puzzle dialog out of the main interface class - this is something that I am going to be working on more in the future and so I wanted it cleanly separated out.

Apart from that, cleaning up the interface code was only a matter of removing unused variables and moving a few blocks of code into their own methods.

For reasons that will become clear, I added some database connection diagnostics to the server side code.   I also discovered why hibernate was not logging to my database - hibernate uses slf4j, not log4j for its' logging.   Adding the slf4j-log4j.jar bridge sorted that out and now all my logging is going to the same DB.

Copyright © 2018 Crypto League. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.