I am making an app with some friends, and we have decided to go with the MVVM pattern. However, their understanding of the pattern differs from mine.
My question is: If we have a data that we would like to reuse in other views, can we store them as properties in a repository (seeing as the repository pattern is a singleton) and access them from other viewmodels?
Here's a generic example of what I mean:
object AnimalRepository {
val favoriteBreed : Breed? = null
}
and we would access it like so:
class DogViewModel(
application: Application
) : AndroidViewModel(application){
val animalRepository = AnimalRepository
fun setFavoriteBreed(favBreed: Breed) {
animalRepository.favoriteBreed = favBreed
}
fun getFavoriteBreed() : Breed {
return animalRepository.favoriteBreed
}
In this case, i did not make use of LiveData for simplicity purposes.
The debate arose from our different interpretations of this section of Android's guide to app architecture: https://developer.android.com/jetpack/docs/guide#truth