java8-the-missing-tutorial icon indicating copy to clipboard operation
java8-the-missing-tutorial copied to clipboard

Confusing at Static Factory Methods

Open hukacode opened this issue 8 years ago • 0 comments

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.

hukacode avatar Sep 29 '16 09:09 hukacode