Notes on ‘Refactoring ‘ — 3.3 Replace Type Code with Class

Before Refactor

 static final int MAN = 1;
 static final int WOMAN = 2;

After Refactor  — Option1

  enum Gender{

After Refactor  — Option2

   class Gender{
     static final Gender MAN = new Gender(1);
     static final Gender WOMAN = new Gender(2);
     private Gender(int value){

Benefits: Type Safe

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.