What is the MVVM"

From Documentation
m (divided content into sections)
Line 1: Line 1:
 
{{ZKEssentialsPageHeader}}
 
{{ZKEssentialsPageHeader}}
 +
__TOC__
  
MVVM is an abbreviation of a design pattern named Model-View-ViewModel which originated from Microsoft.[2] It is a specialization of Presentation Model[3] introduced by Martin Fowler, a variant of the famous MVC pattern. This pattern has 3 roles: View, Model, and ViewModel. The View and Model plays the same roles as they do in MVC. The ViewModel in MVVM acts like a special Controller for View which is responsible for exposing data from the Model to the View and for providing required action and logic for user requests from the View.  
+
===MVVM Background===
 +
MVVM is an abbreviation of a design pattern named Model-View-ViewModel. It is a specialization of Presentation Model introduced by Martin Fowler, a variant of the famous MVC pattern. This pattern has 3 roles: View, Model, and ViewModel. The View and Model plays the same roles as they do in MVC. The ViewModel in MVVM acts like a special Controller for View which is responsible for exposing data from the Model to the View and for providing required action and logic for user requests from the View.  
  
 +
===The Benefits of Adopting MVVM===
 
The ViewModel is an abstraction of a View, which contains a View's states and behaviors. But ViewModel should contain no reference to UI components and knows nothing about View's visual elements. Hence there is a clear separation between View and ViewModel, this is also the key characteristics of MVVM pattern. From another angle, it can also be said that the View layer is kind of like an UI projection of the ViewModel.  
 
The ViewModel is an abstraction of a View, which contains a View's states and behaviors. But ViewModel should contain no reference to UI components and knows nothing about View's visual elements. Hence there is a clear separation between View and ViewModel, this is also the key characteristics of MVVM pattern. From another angle, it can also be said that the View layer is kind of like an UI projection of the ViewModel.  
  
Since the ViewModel contains no reference to UI components, it needs a mechanism to synchronize data between View and ViewModel. Also, this mechanism has to accept the user request from the View layer and bridge the request to the action and logic provided by the ViewModel layer. This mechanism, the kernel part of the MVVM design pattern, is either data synchronising codes written by the application developers themselves or a data binding system provided by the framework. ZK 6 provides a data binding mechanism called ZK Bind to be the infrastructure of the MVVM design pattern and the binder [5]is the key role to operate the whole mechanism. The binder is like a broker and responsible for communication between View and ViewModel.  
+
===The Role of ZK Bind===
 +
Since the ViewModel contains no reference to UI components, it needs a mechanism to synchronize data between View and ViewModel. Also, this mechanism has to accept the user request from the View layer and bridge the request to the action and logic provided by the ViewModel layer. This mechanism, the kernel part of the MVVM design pattern, is either data synchronising codes written by the application developers themselves or a data binding system provided by the framework. ZK 6 provides a data binding mechanism called ZK Bind to be the infrastructure of the MVVM design pattern and the binder is the key role to operate the whole mechanism. The binder is like a broker and responsible for communication between View and ViewModel.  
  
 
[[IMAGE NEEDED]]
 
[[IMAGE NEEDED]]

Revision as of 23:31, 12 February 2012

Stop.png This article is out of date, please refer to http://books.zkoss.org/zkessentials-book/master/ for more up to date information.

MVVM Background

MVVM is an abbreviation of a design pattern named Model-View-ViewModel. It is a specialization of Presentation Model introduced by Martin Fowler, a variant of the famous MVC pattern. This pattern has 3 roles: View, Model, and ViewModel. The View and Model plays the same roles as they do in MVC. The ViewModel in MVVM acts like a special Controller for View which is responsible for exposing data from the Model to the View and for providing required action and logic for user requests from the View.

The Benefits of Adopting MVVM

The ViewModel is an abstraction of a View, which contains a View's states and behaviors. But ViewModel should contain no reference to UI components and knows nothing about View's visual elements. Hence there is a clear separation between View and ViewModel, this is also the key characteristics of MVVM pattern. From another angle, it can also be said that the View layer is kind of like an UI projection of the ViewModel.

The Role of ZK Bind

Since the ViewModel contains no reference to UI components, it needs a mechanism to synchronize data between View and ViewModel. Also, this mechanism has to accept the user request from the View layer and bridge the request to the action and logic provided by the ViewModel layer. This mechanism, the kernel part of the MVVM design pattern, is either data synchronising codes written by the application developers themselves or a data binding system provided by the framework. ZK 6 provides a data binding mechanism called ZK Bind to be the infrastructure of the MVVM design pattern and the binder is the key role to operate the whole mechanism. The binder is like a broker and responsible for communication between View and ViewModel.

IMAGE NEEDED

Next ZK Essentials delves into using the MVVM to handle the shopping cart portion of the application.



Last Update : 2012/02/12

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.