I would say this is a special case of a lookup table. I would not call it a design pattern because those are larger and more abstract. This is an implementation detail.
For example this can be used in the strategy pattern:
static KnotStrategy getKnotStrategy(String name) {
switch(name.toLowerCase()) {
case "slip": return new SlipKnot();
case "granny": return new GrannyKnot();
case "bowline" return new BowlineKnot();
default: throw new IllegalArgumentException();
}
}
As opposed to the lookup:
static final Map<String, Supplier<KnotStrategy>> KNOTS = (
new HashMap<String, Supplier<KnotStrategy>>()
);
static {
KNOTS.put("slip", SlipKnot::new);
KNOTS.put("granny", GrannyKnot::new);
KNOTS.put("bowline", BowlineKnot::new);
}
static KnotStrategy getKnotStrategy(String name) {
Supplier<KnotStrategy> supp = KNOTS.get(name);
if(supp != null) {
return supp.get();
}
throw new IllegalArgumentException();
}
But it's not part of the strategy pattern.