From the course: Android Development Essential Training: Manage Data with Kotlin

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Acquire data in a repository class

Acquire data in a repository class

From the course: Android Development Essential Training: Manage Data with Kotlin

Start my 1-month free trial

Acquire data in a repository class

- [Narrator] An android app can acquire data from multiple sources. To make this manageable and to hide the source of your data from the rest of the application, Google recommends using a software pattern called a repository. A repository is just a simple class, it doesn't extend any special super class, but its job is to encapsulate all of the logic for getting your data. Decisions such as whether to get the data from a web service or from locally cached data can be held in the repository and the rest of the app can simply ask the repository for the data without knowing where it comes from. To implement this, I'll go to my data package and create a new Kotlin class that I'll name monster repository. Now I'll move a bit of code over from the view model. I'll start with this list type property. This is a detail of data acquisition that the view model doesn't need to know about. So I'll cut and paste that into the repository class. Next I'll take this parse text function, I'll cut it to…

Contents