类之中有一个数值类型码,但它不影响类的行为
public class Person {public static final int O = 0;public static final int A = 1;public static final int B = 2;public static final int AB = 3;private int bloodGroup;public void setBloodGroup(int arg) {this.bloodGroup = arg;}public int getBloodGroup() {return bloodGroup;}
}
重构:用一个新的类替换该数值类型码
public class Person {private BloodGroup bloodGroup;
}public enum BloodGroup {O,A,B,AB
}