Now I have an existing class that I would like to refactor to be an Enum. The class currently extends another class which is from external library. As I still would like to benefit from some logics from that extended class meanwhile would like to refactor. How should it be done?
In Java, an enum
class cannot extend another class whereas it can implement interface. Or is it already wrong for the idea of refactoring it to be an Enum? Let me show it in the example code below.
Assume an existing class Existing is extending another class Parent and the Parent class is from an external library and it is NOT an interface.
class Existing extends Parent{
public static final Existing A = new Existing(...);
....
public static final Existing Z = new Existing(...);
public Existing(Srting attr1, String attr1){
super(attr1, attr2);
}
public Existing(String attr1){
super(attr1);
}
}
The idea is to have those static final fields to be Enums, e.g.:
enum NewDesign{
A(attr1, attr2),
B(attr1),
C(attr1, attr2)
//...;
//constructor etc.
//...
}
and possibly when needed, with new extra attr added as below:
enum NewDesign{
A(attr1, attr2, newAttr),
B(attr1, newAttr),
C(attr1, attr2, newAttr),
//...
//constructor etc.
//...
}