title: Is it a bad practice to have methods concerning subclasses in a parent class?
body: <p>I'll start off right with an example to better illustrate what I'm talking about.</p>
  
  <p>Say I have the following classes set up:</p>
  
  <pre><code>public class Vegetable {
  
      public String color;
  
      public int weight;
  
      public boolean isRedTomato() { // &lt;- this is what concerns me
          return this instanceof Tomato &amp;&amp; color.equals("red");
      }
  
      public boolean isBigCucumber() { // &lt;- this is what concerns me
          return this instanceof Cucumber &amp;&amp; weight &gt;= 100;
      }
  
  }
  
  public class Tomato extends Vegetable {
  
      // some tomato specific methods and fields here
  
  }
  
  public class Cucumber extends Vegetable {
  
      // some cucumber specific methods and fields here
  
  }
  </code></pre>
  
  <p>What I like about this is the fact that I can do something like that:</p>
  
  <pre><code>public static void example(Vegetable[] box) {
      for (Vegetable vegetable : box) {
          if (vegetable.isBigCucumber()) { // &lt;- I find this very handy
              System.out.println("Found a big cucumber!");
          }
  
          if (vegetable.isRedTomato()) { // &lt;- I find this very handy
              System.out.println("Found a red tomato!");
          }
      }
  }
  </code></pre>
  
  <p>One may agree that</p>
  
  <pre><code>vegetable.isRedTomato()
  </code></pre>
  
  <p>looks more natural than something like</p>
  
  <pre><code>Tomato.isRedTomato(vegetable)
  </code></pre>
  
  <p>So my question is, how bad that practice would be? What are some other alternatives?</p>