public interface PersonCreationStrategy {
Person create(PersonCreateCommand command);
}
public class PersonCreateCommand {
private String type;
private Map<String , String> params;
}
public class PersonService {
private final Map<String, PersonCreationStrategy> creationStrategies;
public Person create(PersonCreateCommand command) {
PersonCreationStrategy creationStrategy = creationStrategies.get(command.getType());
if (creationStrategy == null) {
throw new UnsupportedTypeException("unsupported type " + command.getType());
}
Person person = creationStrategy.create(command);
return person;
}
}
I have in my app strategy pattern to store into database different type of classes , my main class is Person and other classes inheritance after Person , Person class store all type in SINGLE_TABLE ,
And now I need to do DTO for child classes cause I need return additional values .
Someone could explain it to me ? how to do it in good way ?