Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi Community,

I have these question that came up in my team discussion. I wanted to gather community's feedback on these points. (Legend: V: View, VM: ViewModel, M: Model, IM: interface for ViewModel, INPC: INotifyPropertyChanged)

1. Should VM be agnostic of M?
2. Are V and VM tightly coupled when we say V expects a set of properties from VM?
3. Is it fine to pass M or(IM) inside VM constructor, so that in dual target scenario an M for Desktop can be replaced with that M of silverlight without changing VM?
4. Is it fine to assume that in dual target environment we are more likely to have different M for Desktop and silverlight? Or should we strive to have same M but different VM?
5. Is it correct to always assume that V would be different for Desktop and Silverlight?
6. Is it correct if we strive for a plain VM which just have some properties with getter and setters. And we create an abstraction b/w M and VM lets say A. Our A will listen to changes in M and set the properties in VM. And similarly A will subscribe to INPC of VM, and change the M. In this way we will have a VM which can be used inside Blend. Also our VM will remain same for Desktop and Silverlight so we can package this VM in an independent library(dll). This library will be a public access point. So public API remains same for Desktop and Silverlight.


Please consider that over a period of time many different MVVM concepts have evolved as best practices. So my assumptions below may contradict your's. Please feel free to site some examples as I am very open to change my assumption/opinion.

Thanks in advance :)
Posted

1 solution

1. No. This sounds like you don't fully understand what the model is, and you seem to think the model is just the data entity. It isn't - this is a common misunderstanding based on a belief that MVVM is purely a presentation pattern. It's not, it's an architectural pattern, so the model doesn't just refer to the data entity, it relates to the services that the view/viewmodel rely upon.
2. Yes, the view is coupled to the view model.
3. See my answer to point 1. I would expect services, etc, to be injected into the constructor, or injected via property injection.
4. Why? If the VM doesn't need anything that you can't get in both environments, why should they be different.
5. No.
6. No. That really shouldn't be what you are aiming for.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900