9 The MVVM pattern
In this chapter:
- The Model, View, ViewModel paradigm
- The problems that MVVM solves in complex apps
- Making Controls MVVM friendly with Behaviors
The Model, View, ViewModel (MVVM) pattern was introduced by Microsoft with WPF and has become the standard for apps developed using XAML. It’s a popular pattern with enough nuance that entire books have been dedicated to the subject. This chapter will provide an introduction, and as you progress through your .NET MAUI journey, you may find that this is a topic that you want to explore in more depth.
Use of the MVVM pattern is, in some ways, more an art than a science. You should aim to understand he rules about separating UI logic, presentational logic and business logic if you are adopting the MVVM pattern in your app. Of course, blind adherence to any pattern is an anti-pattern, and you should prioritise ensuring that your code is readable and maintainable. But you can’t make an informed decision about when to deviate from the pattern if you don’t understand it well.