Prism: MVVM vs MVP once again

Topics: Prism v2 - Silverlight 3, Prism v2 - WPF 3.5
Feb 11, 2010 at 12:29 PM

Hi All,

 

On the web, you can find a lot of articles explaining the differences between MVVM / MVP.
Although it's hard to find any advantages of MVVM over MVP.. Could somebody list some?

 

I use MVP, and with all the buzz around MVVM, I'm trying to see what would be better..
In fact, I even see one disadvantage in MVVM:

Suppose you have ViewModel, called CustomerViewModel that represents a Customer model object.
(as in the MVVM example at http://code.msdn.microsoft.com/mag200902MVVM/Release/ProjectReleases.aspx?ReleaseId=2026)
So the CustomerViewModel has a FirstName property, which it gets from the Customer model object like this:

        public string FirstName
        {
            get { return _customer.FirstName; }
            set
            {
                if (value == _customer.FirstName)
                    return;

                _customer.FirstName = value;

                base.OnPropertyChanged("FirstName");
            }
        }

Suppose some other process/view/.. changes the _customer's FirstName, how will this CustomerViewModel, and
as a consequence, it's View, be notified of this change?
- Should a NotifyPropertyChanged listener be attached to the _customer upon CustomerViewModel creation?

With my MVP approach this all happens automatically, as the View binds directly to Customer.FirstName,
with Customer a property on my CustomerPresenter. This seems a very natural thing to do, as WCF proxies etc.
create objects that implement INotifyPropertyChanged, and thus are very easy to bind directly to.

Feb 11, 2010 at 5:20 PM

Hi,

The following articles talk about using MVVM in WPF/Silverlight applications and also compare it with MVP:

As for the particular example you are exposing, the way to achieve this would be raising the PropertyChanged event in the FirstName property setter of the Customer model class. Your VM can then handle this event and if Notify the View using the PropertyChanged event as well.

Another possible way (which would avoid having to raise the event in the ViewModel again), would be exposing the Customer model class instance as part of your ViewModel. If you have a CurrentCustomer property of type Customer in your VM you can use the following syntax for binding:

<TextBlock Text={Binding CurrentCustomer.FirstName}/>

Some time ago I created a blog post that talks about using MVVM with Prism which you might find useful.

Please let me know if this helps.

Damian Schenkelman
http://blogs.southworks.net/dschenkelman

Feb 12, 2010 at 7:29 AM

Thanks for your reply Damian,


Concerning your solutions:
The 1ste: That would be a way to do it, but I think it's double work to first bind your view to the FirstName on the ViewModel, which in turns listens to the FirstName on the actual model.
              That looks to me like a Binding to the ViewModel which in turns "binds" to the Model

The 2nd:  I agree with you that exposing the CurrentCustomer Property resolves the issues of solution 1. But then again, I do not see any difference between this solution and the
              MVP approach... (Quote: "With my MVP approach this all happens automatically, as the View binds directly to Customer.FirstName, with Customer a property on my CustomerPresenter.")

Thanks again,
Koen

Feb 12, 2010 at 10:08 AM
Edited Jan 5, 2011 at 10:58 AM
KoenJans wrote:

Hi All,

On the web, you can find a lot of articles explaining the differences between MVVM / MVP.
Although it's hard to find any advantages of MVVM over MVP.. Could somebody list some?

 You might find the following blog of interest   MVPVM - Model View Presenter View Model.

Coming from CAB and Smart Client Software Factory I am hardcore MVP.   In the WPF environment there is so much we can do with databinding that MVVM is the only logical choice (versus Supervising Controller or Passive View).  However, WPF in the environment of Prism, MEF and Unity (reusable components) with loosely coupled views coupled to shared view models neither MVP or MVVM are efficient alone.   For my personal projects, such as my newly activated http://PasswordMgr.CodePlex.com  (another shameful plug)  I go with MVPVM (blog goes into more detail).