Skip to content

Instantly share code, notes, and snippets.

@chermehdi
Created November 9, 2016 21:23
Show Gist options
  • Save chermehdi/dd15b18b14fd737c189ba6f2a77cf9d2 to your computer and use it in GitHub Desktop.
Save chermehdi/dd15b18b14fd737c189ba6f2a77cf9d2 to your computer and use it in GitHub Desktop.
public class EnemyFactory {
public static Enemy create(EnemyType enemyType) {
Enemy enemy = null;
switch (enemyType) {
case SMALLENEMY:
enemy = new SmallEnemy();
break;
case SMARTENEMY:
enemy = new SmartEnemy();
break;
default:
// throw some kind of exception
throw new RuntimeException("the given enemy type does not existe ");
}
return enemy;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment