googlecodelabs / android-build-an-app-architecture-components

Other
266 stars 133 forks source link

Step 12: What are ViewModelProvider factories for? #32

Closed alvindizon closed 5 years ago

alvindizon commented 5 years ago

Sorry if this may seem too basic, but I can't wrap my head around the concept of ViewModelProvider factories. Why do we need factories? And is this the only way to create viewmodels in an activity? Thanks

alvindizon commented 5 years ago

Okay, based on my understanding, having a factory + using the InjectorUtils is just a way to preserve the so-called "separation of concerns", since you can't take have a reference to the Repository in the View.