title: Checking `instanceof` while iterating through a loop
body: <p>I have class structure where  </p>
  
  <ul>
  <li><code>public abstract class AbstractBuilding</code> <em>implements some non-relevant
  interfaces for this question.</em></li>
  <li><code>public abstract class AbstractAnimalBuilding extends AbstractBuiling</code>
  <br> And small number of classes following this structure: </li>
  <li><code>public class AnimalBuildingA extends AbstractAnimalBuilding</code></li>
  <li><code>public class AnimalBuildingB extends AbstractAnimalBuilding</code></li>
  <li><code>public class AnimalBuildingC extends AbstractAnimalBuilding</code></li>
  <li><code>public class AnimalBuildingD extends AbstractAnimalBuilding</code></li>
  </ul>
  
  <p>In a totally separate class I have the following method:</p>
  
  <pre><code>@FXML
  private Button btnAnimalBuildingA;
  @FXML
  private Button btnAnimalBuildingB;
  @FXML
  private Button btnAnimalBuildingC;
  @FXML
  private Button btnAnimalBuildingD;
  
  for (AbstractAnimalBuilding animalBuilding: animalBuildings){
      if (animalBuilding instanceof AnimalBuildingA) {
          changeButtonDisplay(btnAnimalBuildingA)
      } else if (animalBuilding instanceof AnimalBuildingB){
          changeButtonDisplay(btnAnimalBuildingB)
      } else if (animalBuilding instanceof AnimalBuildingC) {
          changeButtonDisplay(btnAnimalBuildingC)
      } else if (animalBuilding instanceof AnimalBuildingD){
          changeButtonDisplay(btnAnimalBuildingD)
          //Do something specific here
      }
  }
  
  private void changeButtonDisplay(Button buttonToChange){
      button.setVisible(true);
  }
  </code></pre>
  
  <p>Where <code>animalBuildings</code> is a <code>Set&lt;AbstractAnimalBuilding&gt;</code> containing any combination of <code>AnimalBuildingX</code>'s. </p>
  
  <p>Assuming the structure at the top needs to be kept (eg, <code>AnimalBuildingX</code> <strong>HAS</strong> to extend <code>AbstractAnimalBuilding</code>), what would be a better approach than the multiple <code>if-then-else</code> statements in determining what kind of building <code>animalBuilding</code> is?</p>
  
  <p>Would it feasible to simply create a new <code>Interface</code> as outlined in <a href="https://stackoverflow.com/questions/5579309/switch-instanceof">this</a> question and have each <code>AnimalBuildingX</code> <code>implement</code> it while still extending <code>AbstractAnimalBuilding</code> or is there a way I can do it using the structure I currently have. </p>