feat: add CalcFunctionFactory for calculator operations (#13)
CI / build-and-test (pull_request) Successful in 16s
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>
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
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();
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user