Posted by: Zeeshan Amjad | February 7, 2010

Evaluation of MVVM


Let’s take a look at MVVM from higher level and take a step  by step approach to understand it. Here our discussion is based on complexity of the architecture from simple to complex, not from historical order.

Probably the simplest design principle to separate the data from its presentation is Observer design pattern. In observer design pattern, we have two different classes for data (subject/model) or its presentation (observer/view). Subject class contain the instance of all of the observers and send notification to all of observers when there is any change in the data. Here is a simple block diagram of observer design pattern.

MVVM_01

The next step is to introduce middle layer in between data and its presentation. The main purpose of this layer is to communicate between these two component. This is a main concept of Model View Controller (MVC). It is shown by this block diagram.

MVVM_02

This approach has some advantages and disadvantages. The main disadvantage is that our view is not totally independent of our model. Model View Presenter (MVP) handle exactly the same problem. In MVP model there is no relation between View and Model.

MVVM_03

MVVM is very similar to MVP pattern. Or it is some sort of specialized form of MVP pattern. In MVVM Presentator known as ViewModel. Model communicate with ViewModel with notifcation and ModelView communicate with View with data binding and command binding as shown by this block diagram.

MVVM_04 

Now let’s take a look at MVVM little bit more detail. What is the biggest advantage of this. Its first advantage is that our presentation is totally unaware of our model. We don’t write any user interface specific code in ViewModel and all the communication is based on data binding and command binding. It means we can easily write a unit tests for it. We can easily change any user interface or even change the data model easily. Here is a detail block diagram of MVVM.

MVVM_05 

This diagram explain how can we take advantage of MVVM. The most important thing in this pattern is to property design the ViewModel. WPF has very orthogonal design. It means we can customized or enhanced different parts of the library without effecting others. Most of the WPF reusability is based on composition rather than inheritance. Therefore we can take its maximum advantage even at run time. Because we can change the composition behavior at run time easily but not inherited components. In this block diagram we see the major components of WPF class library which we developed, enhanced or customized in most of the WPF application.

MVVM_06

Advertisements

Responses

  1. very helpful

    • Thanks to like it.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: