title: How to tackle following design concern?
body: <p>I have a class</p>
  
  <pre><code>public class MyCompleteObject {
  
     private MyEnumA enumA;
  
     private MyObjectB objectB; 
  
  }
  </code></pre>
  
  <p>EDIT (Making it more clear): enumA and objectB are interdependent. MyObjectB has 3 subclasses. And each value of MyEnumA goes with object of only one of the subclass of MyObjectB</p>
  
  <p>Since MyObjectB has 3 subclasses, so objectB can be of 3 types. MyEnumA has a lot of values (~30, since I need only their text values, couldn't think of any other option than enum, correct me if enum should not have these many values).</p>
  
  <p>So, there can be 30x3 = 90 combinations of MyEnumA and MyObjectB but not all of those 90 combinations are valid. That's where I am stuck. </p>
  
  <p>What would be the best way to address this? Couple of options which I can think of are:</p>
  
  <p>1) Whenever an instance of MyCompleteObject gets created, I should check if enumA and objectB are consistent with each other and throw an exception if they are not consistent (Not feeling very comfortable with this approach). </p>
  
  <p>2) Make a lot of subclasses with different combinations of enumA and objectB. Again, doesn't seem a promising solution as a lot of subclasses will be created depending on different combinations enumA and objectB. </p>
  
  <p><strong>Update 1)</strong></p>
  
  <p>Third approach which I can think of after reading various answers is:</p>
  
  <p>3) First make extensible rick enum types as @scottb's answer tells. Then I think I can make 3 different constructors in MyCompleteObject class as:
  EnumA, EnumB and EnumC are my enums categorized as per their validity with 3 sublclasses of MyObjectB (@scottb's answer). MyObjectBFirst, MyObjectBSecond and MyObjectBThird are the three subclasses of MyObjectB. </p>
  
  <pre><code>public MyCompleteObject(EnumA enumA, MyObjectBFirst objectB){//}
  
  public MyCompleteObject(EnumB enumB, MyObjectBSecond objectB){//}
  
  public MyCompleteObject(EnumC enumC, MyObjectBThird objectB){//}
  </code></pre>
  
  <p>This can ensure compile time checking. However, 3 different constructors are there. I also looked into builder pattern but couldn't fit it here. It was oriented towards adding up optional arguments, but here I have conditional arguments and all are required. </p>
  
  <p>Thanks!</p>