what is mvvm

10 months ago 24
Nature

MVVM stands for Model-View-ViewModel and is an architectural pattern in computer software that separates program logic and user interface controls. It was invented by Microsoft architects Ken Cooper and Ted Peters specifically to simplify event-driven programming of user interfaces. The ultimate goal of MVVM architecture is to make the view completely independent from the application logic. The pattern is often used in Windows and web graphics presentation software.

The MVVM pattern consists of three core components: the model, the view, and the view model. Each serves a distinct purpose. The model represents the app’s domain model, which can include a data model as well as business and validation logic. The view is the collection of visible elements, which also receives user input. The content of the view is not interacted with directly to change what is presented. The view model is located between the view and model layers. This is where the controls for interacting with the view are housed, while binding is used to connect the UI elements in the view to the controls in the view model.

The view model of MVVM is a value converter, meaning it is responsible for exposing (converting) the data objects from the model in such a way they can be easily managed and presented. In this respect, the view model is more model than view, and handles most (if not all) of the views display logic. The view model may implement a mediator pattern, organizing access to the back-end logic around the set of use cases supported by the view.

The key to using MVVM effectively lies in understanding how to factor app code into the correct classes and how the classes interact. The MVVM pattern helps cleanly separate an applications business and presentation logic from its user interface (UI), making an application easier to test, maintain, and evolve.