I agree that it is confusing and overworking.
But I really think that the code is quite object oriented. This is an example of a strategy. The code that generates the answer list does not care how the answers are calculated - the two problems are separated, and a different calculation strategy can be applied without having to touch the code that generates the list.
To make the class more useful, these functions should be passed from the outside (for example, dependency injections), and not created in the constructor.
You know the answer, I suppose, but why is it worth it ...
public Solver() { functionList = new ArrayList<MathFunction>(); functionList.add(new MathFunction() { @Override public double calculate(double x) { return 1d/x; } }); functionList.add(new MathFunction() { @Override public double calculate(double x) { return Math.sqrt(x); } }); }
aetheria Aug 21 2018-12-18T00: 00Z
source share