MVVM is all about the separation of concerns. Each part has a specific meaning:
- Model: This relates to anything that represents data and that can be referenced with ViewModel.
- View: This is the visual component. In Xamarin.Forms, this is represented by a page.
- ViewModel: This is the class that acts as the glue between the model and the view.
In our app, we could say that the model is the repository and the to-do list items it returns. ViewModel refers to this repository and exposes properties that the view can bind to. The ground rule is that any logic should reside in ViewModel and no logic should reside in the view. The view should know how to present data, such as converting a Boolean value into Yes or No.
MVVM can be implemented in many ways and there are quite a few frameworks that we can use to do so, such as Prism, MVVMCross, or even TinyMvvm. In this chapter, we have chosen to keep things simple and implement MVVM in a vanilla way, without any framework at all.
The main benefits of using MVVM as an architectural pattern are a clear separation of concerns, cleaner code, and great testability of ViewModel.
Well, enough of that—let's write some code instead!