Yes, you are headed in the right direction.
You’ll need a constructor to assign the passed objects to your member fields.
Make your member fields final
to prevent their reassignment to another object reference.
public enum Type {
// Enum objects.
TYPE1("type_name_1", new TypeObj1()),
TYPE2("type_name_2", new TypeObj2());
// Member fields.
final TypeInterface typeObj;
final String value;
// Constructor.
Type( final String value , final TypeInterface typeInterface ) {
this.typeObj = typeInterface ;
this.value = value ;
}
}
Tip: This kind of thought exercise is more clear and productive if you devise a simple but semi-realistic scenario rather than your amorphous “TypeInterface” and “value”.
public enum Pet {
// Enum objects.
FLUFFY( "tuxedo" , new Cat() ),
ROVER( "chocolate Lab" , new Dog() );
// Member fields.
final Animal animal;
final String description;
// Constructor.
Type( final String desc , final Animal animal ) {
this.animal = animal ;
this.description = desc ;
}
}