“Binders and boxes on shelves in a large archive” by Samuel Zeller on Unsplash

In this post I’m am going to discuss a good way to store/ cache/ and load data. Most of today’s apps rely on a server to display information. In combination with a cache, a database and error handling, this can become pretty messy. Luckily there is a design pattern which makes accessing data very convenient and easy.

Without a pattern:

Before v3

Each screen needs data, and therefore requests the network to load it. Let’s say you also want to have a cache, now every screen first needs to check the cache and then the network. Everything added to the data layer is reflected inside UI code.

The code is tightly coupled and not well organized, the question arises why the screen manages the data.

Introducing the repository:

After v3

A repository is a datasource. To be more specific, to the rest of the app, it’s the only datasource. Screens requesting data don’t necessarily need to know where it is coming from. This allows all data related operations to be in one place. Refactoring and modifying becomes easy and accessing the data even easier.