I have several Bot
objects:
Slicer
Bomber
Tower
Zombie
Fly
Slime
Soldier
...
I want to build a bot factory. Is passing a class type to the constructor an anti-pattern?
public class BotFactory {
public static Bot create(Game game, Class<? extends Bot> botClass) {
Bot bot = null;
if (botClass == Soldier.class)
bot = new Soldier(game, 0, 0);
else if (botClass == Slicer.class)
bot = new Slicer(game, 0, 0);
// ...
return bot;
}
}
Aucun commentaire:
Enregistrer un commentaire