Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am currently working on a WP8 application. My current design is to have each view bind against a specific view model directly.

Looking through the samples though, it seems that another way is to have all the view models accessed through the Main View Model and then have all the views to their view models through the MVM.

Is this the correct way to do it (So that it doesn't cause flexibility and other issues in the future)?

share|improve this question
    
+1 for the excellent article link. That article helped me in the past to gain a much more thorough understanding of how the MV* patterns relate and how they are modified to best suit the project's needs. –  CodexArcanum Nov 29 '12 at 5:14
add comment

1 Answer 1

up vote 3 down vote accepted

Generally, yes, MVVM leads to a 1:1 binding between Views and ViewModels. It's not a requirement, but seems to be a side-effect of how most people are writing MVVM structured applications.

It is possible to have one or more Views pointing to the same ViewModel. The VM merely needs to provide the properties that the specific View requires for the VM to be useful.

I would shy away from a hub-spoke pattern using a "main" VM that provides access to the other VMs. Sounds like more overhead than necessary without adding much benefit.

There's an alternative pattern called MVPVM that's a pretty useful read even if you're going to stick with the MVVM pattern. MVPVM separates out the business logic from the VM and places it within the Presenter.

What I really liked about the article is it gives the progression of MVC -> MVP in the smalltalk days, then explains how MVP remained relevant for a lot of today's UI's and the natural progression into MVVM from MVP. The author gives a caveat about not discussing web applications, only desktop applications, but I think the article is broad enough to where you can glean the relevant details regardless of your target application.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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