title: Java: Get attribute of subclass without casting
body: <p>Let's say I have a superclass <code>Order</code> and two subclasses <code>VehicleOrder</code> and <code>TaskOrder</code>. Both inherrit a lot of methods from the superclass, but have one specific field: <code>VehicleOrder</code> has a <code>Model</code> and <code>TaskOrder</code> has a task.</p>
  
  <p>Now, in an other class, I have a List of <code>Order</code>. In that method, I need to do calculations based on the order's specific field.</p>
  
  <p>My solution for now is 'polluting' the superclass <code>Order</code> with two methods <code>getModel()</code> and <code>getTask()</code>, which return null by default and can be overriden by the subclasses. The other class then checks for null and if not null, makes the calculations. This doesn't feel like the right way to do this though...</p>
  
  <p>As I don't know the subclass-types of the general list of orders in the other class, I can't cast to get the attribute.</p>
  
  <p>The only other way to fix this is using the <code>Visitor pattern</code> , but that feels like a bit of overkill.. Is it?</p>
  
  <p>Is there a clean way to do this?</p>