Currently I have a method that acts as a factory based on a given String. For example:
public Animal createAnimal(String action)
{
if (action.equals(\"M
And what do people think about using Class.newInstance() inside Tom Hawtin's answer? This will avoid us from storing unnecessary anonymous classes in memory? Plus code will be more clean.
It will look something like this:
private static final Map factoryMap =
Collections.unmodifiableMap(new HashMap() {{
put("Meow", Cat.class);
put("Woof", Dog.class);
}});
public Animal createAnimal(String action) {
return (Animal) factoryMap.get(action).newInstance();
}