Are the advantages of Model-View-ViewModel (MVVM) pattern worth the overhead?

前端 未结 4 1414
执笔经年
执笔经年 2021-01-04 21:15

The question is stated in the subject: are the advantages of Model-View-ViewModel (MVVM) pattern worth the overhead?

In many cases, implementing the view model invo

相关标签:
4条回答
  • 2021-01-04 21:43

    Why not extending the Model class, providing additional properties to make it easy to be consumed by the View instead?

    Effectively that is what the PresentationModel is for. Which MVVM is strongly based on. The difference is that the ViewModel is the model for the view and not the model for the data. So you are concerned around more how the view behaves with the data.

    If you have a simple UI that all it does is present the model then I would suggest expose the Model on a property of the ViewModel and bind to that. Make sure though the model does implement INotifyPropertyChanged etc.

    The power of the ViewModel is when you have things to do in response to a user action. The ViewModel can then support Commands, calling out to services and validation and thus leaving the Model as a data container

    0 讨论(0)
  • 2021-01-04 21:45

    Why not extending the Model class, providing additional properties to make it easy to be consumed by the View instead?

    In the simple cases, this is all the ViewModel is doing - wrapping up the Model so that its extended in a way that's consumable by the View. If your Model can be bound directly, you're welcome to do so.

    That being said, there is more to the ViewModel layer than just wrapping the model - this is also where the application specific logic - ie: the application's plumbing, will occur. Something has to make the requests from the Model classes correctly and compose together the logic.

    0 讨论(0)
  • 2021-01-04 21:51

    If you are concerned about extra work, you can always create a ViewModelBase (INotifyPropertyChanged , Errors/Validation, generic stuff) to be inherited by your ViewModel, it will minimize things that you think may cost you time to replicate. And also, Silverlight/Wpf provides us with binding which greatly reduces our coding, besides the fact that XAML also does that by providing functionalities through markup. Besides that you can further the design by using screens, controllers, etc.

    For me, I do not see any "overhead" with regards to using MVVM; if there were, it'd be worth it. It properly deals with the Separation of Concerns. It provides a good platform for development especially in teams where people may take care of different aspects of the application without affecting other team members codes (especially between developers and designers).

    Hope this helps

    0 讨论(0)
  • 2021-01-04 22:00

    Benefits of MVVM

    1. Reduced complexity.
    2. Isolation of Designing and Development.
    3. Dependency injection.
    4. Major advantage is when you have a Well MVVM structured Windows Phone application and want to develop same for Windows Metro Desktop, Only thing u want to concentarte on design as the same view model can be used as it is.

    Hope it helps.

    0 讨论(0)
提交回复
热议问题