title: Elegant way to create one of a large number of classes
body: <p>For context, I'm trying to make a game something along the lines of Pokemon. You obtain, train and fight monsters.</p>
  
  <p>Each species of monster is a class inheriting from an abstract base class (so they can have unique behaviour), and hopefully there will be a very large number of different species throughout the game. Ex:</p>
  
  <pre><code>abstract class Monster {
    int hp;
    void attack();
    //Etc.
  }
  
  public class FireBreathingDragon extends Monster {
    static String species_name = "Fire Breathing Dragon";
    //Blah
  }
  </code></pre>
  
  <p>So when the player is exploring, they will encounter monsters local to an area at random. The game then needs to create a monster at random from a list of species that live in that area. Now to make this code reusable between areas (and make it easy to create monsters dynamically in other places in the code) I don't want to hardcode the possibilities into the area. Instead I think I'd like something along the lines of a factory that creates a monster of a given species on demand, something like:</p>
  
  <pre><code>public class MonsterFactory {
    Monster createMonster(
      String species_name,
      //Possibly other paramters
    );
  }
  </code></pre>
  
  <p>The problem is then implementing <code>createMonster</code> in a "nice" or "elegant" way when you have (potentially) tens or hundreds of different Monster classes. Of course you could use a very very long <code>if-else if-else</code> or <code>switch</code> statement, but that's horrible to write and extend. Is there a nice way to do this? It would also be good if it was relatively easy to extend when adding more monsters.</p>
  
  <p>Or is there some totally different design I should be using instead?</p>
  
  <p>Disclaimer: My java is a little rusty, syntax may not be perfect, sorry about that.</p>