blob: 7bb5ee99d804b59c4ec21cece9f629a2996a54d3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
public class FibonacciCalculatorImpl implements FibonacciCalculator {
private final FibonacciNumberFactory factory;
public FibonacciCalculatorImpl(FibonacciNumberFactory factory) {
this.factory = factory;
}
@Override
public int calculateFibonacci(FibonacciNumber fib) {
if (fib.getNumber() <= 2) {
return 1;
}
else {
return factory.getFibonacciNumber(fib.getNumber() - 1).calculate(this) + factory.getFibonacciNumber(fib.getNumber() - 2).calculate(this);
}
}
}
|