Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing at Static Factory Methods #20

Open
hukacode opened this issue Sep 29, 2016 · 0 comments
Open

Confusing at Static Factory Methods #20

hukacode opened this issue Sep 29, 2016 · 0 comments

Comments

@hukacode
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant