55e5cbeb0f
CI / build-and-test (pull_request) Successful in 16s
Callers pick an operation via the CalcOperation enum instead of instantiating implementation classes directly. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
21 lines
598 B
Java
21 lines
598 B
Java
package com.example.util;
|
|
|
|
public final class CalcFunctionFactory {
|
|
|
|
private CalcFunctionFactory() {
|
|
}
|
|
|
|
public static CalcFunction create(CalcOperation operation) {
|
|
if (operation == null) {
|
|
throw new IllegalArgumentException("Operation must not be null");
|
|
}
|
|
return switch (operation) {
|
|
case ADD -> new AddFunction();
|
|
case SUBTRACT -> new SubtractFunction();
|
|
case MULTIPLY -> new MultiplyFunction();
|
|
case DIVIDE -> new DivideFunction();
|
|
case POWER -> new PowerFunction();
|
|
};
|
|
}
|
|
}
|