title: Java Interface that forces implementation of an enum - How to approach?
body: <p>I have a situation where I would like to used an instance of an object called Abstraction, which would be a Java interface looking something like:</p>
  
  <pre><code>public interface Abstraction {
     public enum Actions {
     }
  }
  </code></pre>
  
  <p>The idea being that any class implementing Abstraction has to implement enum Actions (I realise this doesn't work).</p>
  
  <p>A class implementing the interface may look like:</p>
  
  <pre><code>public class AbstractionA implements Abstraction {
     public enum Actions {
      f, c, r, a
     }
  }
  </code></pre>
  
  <p>In another class I would want to create an Abstraction object like:</p>
  
  <pre><code>Abstraction abs = new AbstractionA();
  </code></pre>
  
  <p>and then be able to access the enum values applicable to the Abstraction object created, e.g.</p>
  
  <pre><code>abs.Action.r;
  </code></pre>
  
  <p>I realise my approach to this is all wrong but cannot see an appropriate way to handle this type of situation. How can I implement something like this where different implementations of the interface have a varying subset of the options I would generally want to put in an enum?
  Perhaps I can implement the enum with all possible options in the interface and then somehow restrict implementations of the interface to using a subset of those enum values?</p>
  
  <p>EDIT:
  Another example implementation might be</p>
  
  <pre><code>public class AbstractionB implements Abstraction {
     public enum Actions {
      f, c, b, r, a
     }
  }
  </code></pre>
  
  <p>I think I have figured out a way forward with this:</p>
  
  <pre><code>public interface Abstraction {
     public enum Actions {
      f, c, b, r, s, a  
     }
     public Actions[] availableActions();
  }
  </code></pre>
  
  <p>Then implement with:</p>
  
  <pre><code>public class HunlAbstractionA implements Abstraction{
     @Override
     public Actions[] availableActions()
     {
      Actions[] actions = new Actions[] {Actions.f, Actions.c, Actions.r, Actions.a};
      return actions;
     }
  }
  </code></pre>
  
  <p>This way I have access to all possible actions listed in the interfaces enum and can make checks to ensure an Action to be dealt with is one of the availableActions for the created class. </p>