Should I implement business logic on a Model or a ViewModel

后端 未结 4 716
走了就别回头了
走了就别回头了 2021-01-04 11:28

When I\'m processing business logic in an MVVM app. Should I do this on the Model or the ViewModel?

For example, if I want to re-calculate costs after an Asset has b

4条回答
  •  醉梦人生
    2021-01-04 11:57

    Use the model if you are building a web app; and one level bellow the model i.e. the domain level if you are building a LAN/desk app.

    Your problem - re-calculate costs after an asset has been re-valued - might not just be a user interface issue. A back-end application might want to do the same (for example, for automatically importing data). And then you have a choice of either duplicating business logic or rewiring to existing one.

    Nothing wrong with using the same model for the back-end too. But models -especially disconnected ones- tend to be large data structures because they need to bring with them all data from reference tables (unless you want to do round trips to server and sacrifice your GUI experience). And that might affect performance if model is used.

提交回复
热议问题