Repository Pattern – How to Describe the Repository Pattern

designdesign-patternsrepository

I'm currently working on the project with the new team and they are using Repository pattern which is new to me. In this repository, they're currently doing

1.If we are offline, we will load data from file
2.Otherwise, we will make an api call to get data from server.

I did some researches and noticed that Repository is providing basic CRUD operations to local database. However, if we consider Repository acts like Data Access Layer, it can make an api call to retrieve data remotely as well.

Which one is the correct way to follow. Any ideas ?

Best Answer

The purpose of a Repository is to provide an abstraction layer for data access. That abstraction layer should shield the user of the repository from the details of accessing the data. Things like connection strings, data sources, switching to a different data source... Your user shouldn't have to worry about those things.

In other words, the user of a Repository should not have to be concerned about where the data is coming from. That is an implementation detail. How you implement that detail is entirely up to you and your software's specific requirements.

Related Topic