I am trying to learn Android on the side and I have been doing some research and figure the MVVM pattern is the route I want to go. I have some familiarity with it with WPF/XAML. However, I do have a question about how the View (Activity / Fragment) is inflated.
This is my general understanding of the Design Pattern:
The Model sits at the bottom layer. This layer will have the business logic and the Entities. For each declared Entity, a table is stored in the SQLite database using Room. To adhere to encapsulation, all data members are private and only accessible through get()
methods.
The Data Access layer stores my Database and a DAO for an Entity. It is my understanding that the DAO is the Object responsible for interacting between the View Model and the Database.
The View Model is how the data is exposed. It will interact with the Repository to ultimately access the database since the database will be referenced in the Repository.
The View Model and the View relationship is where I have trouble. The View Model has no understanding of the View, I understand, but how do Views get inflated? I know this is incorrect - but my thought process is if you use DataBinding to bind, for example, an onClick
attribute to a method in the ViewModel and suppose this method is responsible for showing a Dialog, then the ViewModel has View knowledge because it is responsible for creating a Dialog.
So essentially, my question is, how does the developer adhere to the MVVM paradigm when it comes to inflating views? If the ViewModel should not be responsible for any View related interactions, only to have its data exposed, is there another layer that I am missing to bridge the inflation?