Hacker News new | ask | show | jobs
by ensiferum 1533 days ago
And the sunset calculator doesn't need a location provider. All it needs are location coordinates which can be given to the calculate function.

In fact the whole thing then becomes a standalone function which takes Location and other relevant parameters and returns the computer sunrise/sunset values. Pure function and super easy to unit test.

If one needs to do a lot of "mockups" for your unit tests then maybe one needs to consider the API and class design. Removing needless coupling helps testability by removing the need to use mocks in the first place.

1 comments

In design terms, I would claim that Sunset Calculator is a "component" (an integration of units), with a "required interface" (i.e. abstracted) that provides the coordinates.

A role of one unit inside this component is to use the provided coordinates and only perform the calculation.