TypeSafeEnum coding pattern was a big time favorite in the past since Java did not have "enum". So people have to invent a way to implement enums. Anyways, Java introduced enum in the recent versions (v1.5+).
Option 3: enum with an abstract method
public enum EmployeeType {
FullTime {
public String getDesc() {
return ("Regular Full Time employee");
}
},
PartTime {
public String getDesc() {
return ("Contractor or Part Time employee");
}
};
public abstract String getDesc();
}
So now one can use enum the similar way it was done in TypeSafeEnum patterns.
Few ways to define enums in Java.
Option 1: Simple enum
public enum Action {
update,
write,
read,
delete
};
Option 2: enum with a constructor
public enum EmployeeType { FullTime("Regular Full Time employee"), PartTime("Contractor or Part time employee"); private String desc; EmployeeType(String desc) { this.desc = desc; }}Option 3: enum with an abstract method
public enum EmployeeType {
FullTime {
public String getDesc() {
return ("Regular Full Time employee");
}
},
PartTime {
public String getDesc() {
return ("Contractor or Part Time employee");
}
};
public abstract String getDesc();
}








