Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Hw17 replace type code with class Refactoring

633 views

Published on

example of Replace Type Code With Class Refactoring

Published in: Technology, News & Politics
  • Be the first to comment

  • Be the first to like this

Hw17 replace type code with class Refactoring

  1. 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-2012Replace Type Code with Class?I am posting code for the "Replace Type Code with Class" refactoring. Kerievsky mentions thatthe primary motivation is to make code type safe. I think that other way to do that is to constrainthe possible values and their accuracy during run-time. In my MSs project I have strings forglassFishHome and db tables. My refactoring would be creating a class called GlassfishHome tomanage validations and correct assignation of values, for example: I would program a directorycontent verification method to confirm whether the correspondent folders/files structure is of aGlassfish server. I would do similar validation for Table; but, as I already had a Table class, I willonly 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 classescode in the next svn trunk URLs:http://java.net/projects/spotlight/sources/svn/content/trunk/RADK/RadkFinal/src/radk/wsgenerator/RESTfulGenerator.java?rev=347 andhttp://java.net/projects/spotlight/sources/svn/content/trunk/RADK/RadkFinal/src/radk/wsgenerator/WebServiceGenerator.java?rev=347public class RESTfulGenerator implements Generator {private static String glassFishHome;...public class WebServiceGenerator {static StringBuilder buffer = new StringBuilder();static String Table = new String();

×