Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Hw17 replace type code with class Refactoring
1. UTAH STATE UNIVERSITY
COMPUTER SCIENCE
CS-7350
“Protection: Replace Type Code With Class” Chapter 9 by Kerievsky, J.
Jorge Edison Lascano
Spring 2012
03-28-2012
Replace Type Code with Class?
I am posting code for the "Replace Type Code with Class" refactoring. Kerievsky mentions that
the primary motivation is to make code type safe. I think that other way to do that is to constrain
the possible values and their accuracy during run-time. In my MS's project I have strings for
glassFishHome and db tables. My refactoring would be creating a class called GlassfishHome to
manage validations and correct assignation of values, for example: I would program a directory
content verification method to confirm whether the correspondent folders/files structure is of a
Glassfish server. I would do similar validation for Table; but, as I already had a Table class, I will
only need to adapt the places where a Table string is used and implement the needed methods.
Here a piece of the original code where the String variables are found. You can find these classes
code in the next svn trunk URLs:
http://java.net/projects/spotlight/sources/svn/content/trunk/RADK/RadkFinal/src/radk/wsgenerat
or/RESTfulGenerator.java?rev=347 and
http://java.net/projects/spotlight/sources/svn/content/trunk/RADK/RadkFinal/src/radk/wsgenerat
or/WebServiceGenerator.java?rev=347
public class RESTfulGenerator implements Generator {
private static String glassFishHome;
...
public class WebServiceGenerator {
static StringBuilder buffer = new StringBuilder();
static String Table = new String();