Monday, January 26, 2015

Refactoring Conway's Game of Life in Java

I've recently revisited the Java version of Conway's Game of Life that I did nearly a year ago, to refactor it using some of the ideas I used in my more recent Clojure version.

This is the UML for the refactored design:


I eliminated the LivingCells class that appeared in the previous design.

I pushed a lot of code from the GameOfLife class into Generation to eliminate a bit of feature envy. This is GameOfLife's code now:

and this is Generation's one:

I also refactored the tests eliminating all the checks based on strings and using constructors with variadic parameters.

Following the idea in the Clojure version I managed to simplify the Rules interface a lot:

Most of the other changes are just renaming of methods, variables and parameters.

This new code keeps the functionality and characteristics of the previous version but it's much simpler.

No comments:

Post a Comment