title: OO Design: inheritance vs type (enum) variable
body: <p>Is there a general best practice when to use inheritance:</p>
  
  <pre><code>public class Information {
    private String text;
  }
  
  public class Message extends Information {
  }
  
  public class Faq extends Information {
  }
  
  public class News extends Information {
  }
  </code></pre>
  
  <p>and when to use enum as a member variable to distinguish:</p>
  
  <pre><code>public enum InformationType {
    MESSAGE, FAQ, NEWS
  }
  
  public class Information {
    private String text;
    private InformationType type;
  }
  </code></pre>
  
  <p>In the code that I work with I have the second - a type field and what bothers me is the code</p>
  
  <pre><code>public void displayInformation(final Information information) {
    if (information.getType == InformationType.MESSAGE) {
       ....
    } else if (information.getType == InformationType.FAQ) {
       ....
    } else if (information.getType == InformationType.NEWS) {
       ....
    } else {
       // some error handling
    }
  }
  </code></pre>
  
  <p>This is definitely a code smell and I don't see how you can have the enum as member variable and not have these if-elses!? If that is true, then you should never have enums as types for the objects, but I see this "pattern" so often!</p>