Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In class today we were introduced to the MVVM architecture for Silverlight/WinPhone/WPF; it looks nice for big projects, but what are your thoughts on MVVM?

What are the pros and cons?

I want to get more into the architecture so that I know when I should use it.

share|improve this question

closed as too broad by gnat, durron597, MichaelT, Kilian Foth, Bart van Ingen Schenau Oct 15 '15 at 10:58

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 11 down vote accepted

MVVM is (yet another) variation on patterns that separate the concerns of a typical presentation, much like MVC and MVP. Regardless of these variations, the basic concerns are the following triad:

  • the Model (the underlying data and domain objects).
  • the View (what the user actually sees and interacts with)
  • the facade that translates between the Model and View. (the ViewModel in this case)

Doing so leads to benefits on it's own that have nothing to do with the platform technology including the increased testability that comes from taking logic that might be lumped into the View otherwise.

The particular slant in MVVM's ViewModel is that it promotes the use of data binding, which is a strong suit of the technologies that tend to use it (wpf, silverlight).

Theoretically, that's it! In practice, this implies skills and experience with data binding. OOP, and testing - so there may be a learning curve. There is also several ways to execute the pattern, so the first few attempts may seem a bit overwhelming.

But you will have the security of your tests as you gain experience and refactor towards more elegant usages. Testing is essential to any non-trivial project IMO, regardless of its ultimate size. Did I mention that MVVM promotes testability?

share|improve this answer

The thing I like most about MVVM (besides the test-ability), at least from a web UI perspective, is that I don't have to write a bunch of plumbing code to wire-up all my event handlers to the page... It's also much easier to think in terms of behaviors and distinct units of responsibility when using this approach.

share|improve this answer

In my experience small projects that are successful become big projects. So always assume your project will be a success and plan for the future. Design it is such a way that you can add on functionality with out forcing it in.

So MVVM is a great tool for just that. Once you set up a few projects and get the hang of it you will find there really is not that much overhead it is just shifting the work from as you go to up front. And once you are ready to go you can take off and create your application. As for when to use it anytime you need a robust dynamic user interface.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.