Android MVVM ViewModel and Repositories for each entity?

1

You should have contextual DAOs, let’s say an UserDao which should contains the queries related to the users, if you have posts in your app, you should have a PostDao for everything related to posts.

2

Same logic for repositories, remember the Single Responsibility Principle for classes, sticking to that principle you should have repositories for each kind of entities separated (UserRepository, PostRepository…).

3

Following all the new concepts described as Jetpack you should have one viewmodel per fragment, unless for one strange reason you have two fragments that need the exact same logic, and that is very unlikely to happen since the objective of a fragment is to be reused.

Leave a Comment