In MVVM, is every ViewModel coupled to just one Model?

前端 未结 7 1122
日久生厌
日久生厌 2020-12-04 17:04

In an MVVM implementation, is every ViewModel coupled to just one Model?

I am trying to implement the MVVM pattern in a project but I found

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-04 17:22

    a viewmodel contains the "view logic" - so all you wanna show on the view is exposed through the viewmodel. if you wanna show data from diffenrent "models" then your viewmodel agregate this and the view can bind to.

    the main purpose from mvvm was btw unit test. this mean easy testing of view logic without UI.

    EDIT: why do you think:

    ViewModel only has one single parameter for the View in its constructor

    EDIT2:

    there btw two main approaches to work with mvvm, first is "View First" second is "Viewmodel First" you can of course mix up both and choose the best approach for you needs.

提交回复
热议问题