Create a Repository Class

First off, a repository isn’t a specific Room-related class but rather a recommended Jetpack convention. The advantage of using a repository is that the ViewModel classes have a single location for all data access, no matter the source of that data. This means that if we were to have web service calls along with our database calls, the front-end components would go to the same place for both and not even care about which was which. Having a repository separates out how you get data with how you use the data.

In our case, having a repository is admittedly overkill since we only have a single data source and, as you’ll see, the functions in our repository will just be pass-throughs to PennyDropDao functions. Still, it’s ...

Get Kotlin and Android Development featuring Jetpack now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.