Separation of Concerns
All good software engineering starts with good separation of concerns. This means knowing what the responsibilities are within the feature and dividing them accordingly between the various actors. In our case, the actors include:
- The Unsplash Store: it makes the API calls to the Unsplash client and fetches the details.
- The API client: responsible for making the server calls, which is done through the pub package.
- The Widgets: rendering surface for the information that is fetched from the API calls and serviced through the store.
Store
The Unsplash Store internally uses the Unsplash Client to make calls to the
server and fetch all the photos. For this it needs the API key to access
Unsplash, which is set up in the init()
method of the FeatureDescriptor
. You
might have seen this in the
article on the FeatureDescriptor.
Widgets
The widget layer always talks to the store and never has direct access to the API client. This is very intentional and also abstracts the details of making server calls from the widgets. Ultimately, what the widgets care about is simply having the information that is to be shown on the screen.
In this feature, we have widgets like the PhotoCard
, PhotoDetail
and
CollectionGridView
which act as a simple Design System layer for the screens.