Skip to content

Confusing at Static Factory Methods #20

Open
@hukacode

Description

@hukacode

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions