MVC / MVP / MVVM What the Heck?

2019-01-30 03:32发布

问题:

I recently worked on a .Net WPF project to build a retail point of sale system where I used the MVP pattern for the first time. It took me a little while to wrap my head around the change of approach but once I did that I thought that the concept rocked!

My question is this: what is the distinction between MVC, MVP and MVVM? If there is a clear distinction, are there guidelines as to when you should use one pattern over another?

If anyone can offer guidance on this, or point to article that explains the differences I'd very much appreciate it.

回答1:

Microsoft's Application Architecture Guide describes MVC and MVP, and explores the differences between the two.

http://www.codeplex.com/AppArch

This MSDN article describes MVVM and it's evolution.

http://msdn.microsoft.com/en-us/magazine/dd419663.aspx



回答2:

It can be hard to grok the differences between patterns by looking at a particular pattern implemented in a particular framework. This msdn article WPF MVVM makes reference to Martin Fowlers original articles which explain a pattern as a general approach:

Back in 2004, Martin Fowler published an article about a pattern named Presentation Model (PM) [...] consider MVVM to be a specialization of the more general PM pattern, tailor-made for the WPF and Silverlight platforms.

So to understand different patterns it is useful to look at Martin Fowler's descriptions of different approaches. His Passive View pattern is the MVP approach. His Supervising Controller pattern is the MVC approach. His Presentation Model pattern is the MVVM approach. This older article takes about the evolution of such patterns.

It may also help to look at implementations in different languages. The article Implementing event-driven GUI patterns using the ZK Java AJAX framework contrasts the three of Martin Fowler patterns mentioned above in a modern Java framework. Even though its a different language and a different framework from WPF it may help to see the pattern rather than the implementation of the pattern to see it done in a different language.