views:

469

answers:

3
+2  Q: 

MVP Vs MVVM - why

Hello,

I was using MVP when I was working with winform. but I moved to MVVM when i started playing with WPF or Silverlight.

The only thing that I noticed is that we don't need to sync with the data between View and ViewModel in MVVM pattern because of powerful binding.

My question are ~

1) Binding (that helps us not to sync View and ViewModel manually) is the only advantage of using MVVM.

2) Is there any other advantage MVVM over MVP? what are the differences?

3) The code below is MVVP pattern or MVVM or both?

interface IView{

  void ShowMessage(string message);

}

class View : IView {
    public void ShowMessage(string message){
              MessageBox.Show(this, message);
    }
}

class ViewModel{

private IView view;

public ViewModel(IVew view){

  this.view = view;

}

........

view.ShowMessage("This is a msg");

}

Thanks.

+2  A: 

Example is MVP, clearly defined by this line:

view.ShowMessage("This is a msg");

While code resulting from MVP and MVVM may look similar in trivial examples, those patterns are significantly different. If you suspect that MVVM is just Microsoft's name for MVP, it's not.

It is Microsoft's name for a less known PM (Presentation Model) pattern - you may want to read up its description.

ima
Yes. Thanks for answering question #3. What about for question 1 and 3? I have read about Presentation Model but I'm not very clear for that. Could you please answer me qustion 1 and 2? Thanks.
Mark
No and Yes. I really don't see point of copy-pasting MSDN here
ima
A: 

I don't think people knows much differences. Otherwise, they could have listed it here..

  • You dont need to sync the data betwen view and viewmodel.
  • one View can have multiple VM.
Michael Sync
A: 

Why MVVM is so "cool", nice post from Jesse Liberty:

http://jesseliberty.com/2010/05/08/mvvm-its-not-kool-aid-3/

Braulio