title: Using enums as a container of implementations
body: <p>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. </p>
  
  <p>I came to the idea, that I could bundle all the visualization types in an enum. I have defined an Interface <em>VectorVisualization</em> and several implementations which implement this interface.</p>
  
  <p>Now I have added to the Interface class the following enum:</p>
  
  <pre><code>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&lt;VectorData&gt; vectors, VectorField field);
     void render(GL gl);
     void clearOldVBOS(GL gl);
  }
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>VectorVisualizationType.CYLINDER.getVisualization()
  </code></pre>
  
  <p>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.</p>
  
  <p>Thanks for your opinion!</p>