I'm currently working on a project where we have to represent a set of vectors in a 3D environment. We have several different visualization implementations.
I came to the idea, that I could bundle all the visualization types in an enum. I have defined an Interface VectorVisualization and several implementations which implement this interface.
Now I have added to the Interface class the following enum:
public interface VectorVisualization {
public enum VectorVisualizationType {
CYLINDER(new VectorVisualizationCylinder(), "Cylinder"),
CONES(new VectorVisualizationCones(), "Cones"),
FATCONES(new VectorVisualizationFatCones(), "Fat cones"),
ARROWS(new VectorVisualizationArrows(), "Arrows");
private final String label;
private final VectorVisualization vis;
VectorVisualizationType(VectorVisualization vis, String label) {
this.vis = vis;
this.label = label;
}
public VectorVisualization getVisualization() {
return this.vis;
}
public String getLabel() {
return this.label;
}
}
void prepareVBO(GL gl, ArrayList<VectorData> vectors, VectorField field);
void render(GL gl);
void clearOldVBOS(GL gl);
}
The label is for a JComboBox in the Gui. So I can now just iterate over the enum and get the label of the different types. Also to set a Implementation I can use the enum like that:
VectorVisualizationType.CYLINDER.getVisualization()
But is this a nice way? Or are there any problems with that approach? Of course, now when you've created a new implementation you have to add this to the enum.
Thanks for your opinion!