In my program, the user needs to input what type of players the game will have. The players are "human"
, "good"
(for a good AI), "bad"
(for a bad AI) and "random"
(for a random AI). Each of these players have their own class that extend one abstract class called PlayerType
.
My struggle is mapping a String
to the object so I can A) create a new object using the String as sort of a key and B) get the related String
from an object of its subclass
Ultimately, I just want the implicit String
to only appear once in the code so I can change it later if needed without refactoring.
I've tried using just a plain HashMap, but that seems clunky with searching the keys via the values. Also, I'm guessing that I'll have to use the getInstance()
method of Class
, which is a little less clunky, which is okay if it's the only way.