I am currently working on a project where we must represent a set of vectors in a three-dimensional environment. We have several different visualization implementations.
I came to the conclusion that I can combine all types of visualization into an enumeration. I have defined the VectorVisualization of an interface and several implementations that implement this interface.
Now I have added the following enumeration to the Interface class:
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 shortcut is for JComboBox in Gui. So now I can just iterate over the renaming and get a shortcut of different types. Also to install the implementation, I can use the enumeration as follows:
VectorVisualizationType.CYLINDER.getVisualization()
But is this a good way? Or is there a problem with this approach? Of course, now that you have created a new implementation, you must add this to the listing.
!