May use functional programming approach with lambdas to map methods to some keys. Here is used Supplier, also may be helpful Function, UnaryOperator, etc.
Have several methods:
public String method1() {
return "";
}
public String method2() {
return "";
}
public String method3() {
return "";
}
Map methods to some keys:
Map<String, Supplier<String>> functions = Map.of(
"abc", () -> method1(),
"def", () -> method2(),
"ghi", () -> method3()
);
Given a key get a particular method from a Map, run it and return a result.
public String request(String key) {
Supplier<String> supplier = functions.getOrDefault(key, () -> null);
return supplier.get();
}
Dictionary Dispatch Pattern.