java8-the-missing-tutorial
java8-the-missing-tutorial copied to clipboard
Confusing at Static Factory Methods
Hi,
At https://github.com/shekhargulati/java8-the-missing-tutorial/blob/master/01-default-static-interface-methods.md, I saw:
Calculator calculator = new BasicCalculator();
int sum = calculator.add(1, 2);
BasicCalculator cal = new BasicCalculator();
int difference = cal.subtract(3, 2);
Oh no! Users of the API are not coding to Calculator interface -- instead, they are coding to its implementation. Your API didn't enforce users to code to interfaces, as the BasicCalculator class was public.
But I don't know why you say "Oh no". Can you explain more?
Regards, Huka.