Hi I want to create factory which will return objects of some supertype based on string parameter(it's a class name)
I found next working solution:
export class ActionFactory {
private constructor() {
}
public static getAction(actionType: string): GameAction {
return new ActionStore[actionType]();
}
}
const ActionStore: any = {
death: Death,
meleeAttack: MeleeAttack
}
The problem here that everytime i'm adding new action i need to add it to ActionStore map. Moreover factory have dependency(imports) for all actions. Is it possible to remove actionstore and make factory independent of action classes? Is it possible to convert string to classname and create new object of this type?
ADD: I have Death and MeleeAttack classes in separate files
export class Death{
public constructor() {
}
//some methods
}
Thanks