0Pricing
Android Academy · Lesson

Repository Pattern

Separate data access from UI with the Repository pattern. Coordinate between Room database and network API as single sources of truth.

Why a Repository?

As your app grows, the ViewModel can become cluttered with data-access code (Room queries, Retrofit calls, SharedPreferences reads).

The Repository pattern moves all data access behind a single class. The ViewModel only talks to the Repository — it doesn't care where the data comes from.

The Architecture Layers

The recommended Android architecture has three layers:

  • UI Layer — Activity/Fragment shows data, sends user events
  • ViewModel — holds state, processes events, calls Repository
  • Repository — fetches data from Room (local) or Retrofit (remote), decides which source to use

All lessons in this course

  1. ViewModel & LiveData
  2. Room Database
  3. Coroutines & Suspend Functions
  4. Repository Pattern
  5. Navigation Component
  6. Dependency Injection with Hilt
← Back to Android Academy