title: Java - alternative to many else if statements with instanceof conditions
body: <p>I have this messy code that I really want to clean up because it has about 12 else if's and each of these if statements check for the instanceof 2 objects, so something like:
  If (parentObj instanceof superclass &amp;&amp; parentObj2 instanceof superclass) </p>
  
  <p>Each if statement executes something different, so polymorphism I think won't make it any better. Also because 12 different super classes for this little functionality (most if statements execute 1 liners) would be a bit ridiculous. 
  And another reason why polymorphism wouldn't work is because I do not have access to the parent class or the super classes. I know that many instanceof conditions is generally not good to do, even though I never really understood why. The methods that are executed inside each if statement are not of the parent class, but are of the super classes, so that's why I need to check for their types so that I can cast them and execute those methods. 
  Any ideas as to how I can clean this up? 
  Thanks! </p>
  
  <p>EDIT: Sorry for the lack of detail, I wrote this on my phone. Anyway below is an example of what I am dealing with. I have looked at the strategy pattern, and my only concern with that was for the same reason that I would have to create many different classes and I felt like creating many different objects just to execute 1 liners all of the time would be a bit wasteful. Also it looks like to me that in a strategy design, I would still have to have the many instanceof checks to know which strategy to execute. Anyway, below is some code :p</p>
  
  <pre><code>if (plotBlockState instanceof Sign &amp;&amp; UpgradeBlockState instanceof Sign) {
      //do Sign Stuff
  }
  else if (plotBlockState instanceof Chest &amp;&amp; UpgradeBlockState instanceof Chest) {
      //do Chest Stuff
  }
  else if (plotBlockState instanceof Dispenser &amp;&amp; UpgradeBlockState instanceof Dispenser) {
      //do Dispenser Stuff
  }
  else if (plotBlockState instanceof Furnace &amp;&amp; UpgradeBlockState instanceof Furnace) {
      //do Furnace Stuff
  }
  else if (plotBlockState instanceof BrewingStand &amp;&amp; UpgradeBlockState instanceof BrewingStand) {
      //do Brew Stand Stuff
  }
  else if (plotBlockState instanceof Hopper &amp;&amp; UpgradeBlockState instanceof Hopper) {
      //do hopper Stuff
  }
  else if (plotBlockState instanceof Dropper &amp;&amp; UpgradeBlockState instanceof Dropper) {
      //do dropper Stuff
  }
  else if (plotBlockState instanceof Beacon &amp;&amp; UpgradeBlockState instanceof Beacon) {
      //do beacon Stuff
  }
  else if (plotBlockState instanceof CreatureSpawner &amp;&amp; UpgradeBlockState instanceof CreatureSpawner) {
      //do spawner Stuff
  }
  else if (plotBlockState instanceof NoteBlock &amp;&amp; UpgradeBlockState instanceof NoteBlock) {
      //do noteblock Stuff
  }
  else if (plotBlockState instanceof Jukebox &amp;&amp; UpgradeBlockState instanceof Jukebox) {
      //do jukebox Stuff
  }
  else if (plotBlockState instanceof Skull &amp;&amp; UpgradeBlockState instanceof Skull) {
      //do skull Stuff
  }
  else if (plotBlockState instanceof CommandBlock &amp;&amp; UpgradeBlockState instanceof CommandBlock) {
      //do commandblock Stuff
  }
  </code></pre>