简体   繁体   中英

Building an Application using MVVM

I need some help to architect an MVVM application. This time I want to do it in the right way.

My View is bound to the ViewModel which is bound to the Model . No problem there. Displaying data is not the problem, updating it is my problem. So when the View asks the ViewModel to update the Model (with a Command ), which need to handle the logic? In my case updating the data is not trivial, there are many calculations with many files. Also, I really want that the Model does not know the business logic. So how to do this? A property in the Model which indicates that the he wants to be updated? Or maybe the ViewModel have to know the business logic? Is it the Best practice?

The model is really a snapshot of the state of your business data. Your non-trivial calculations can be encapsulated in services that can be abstracted behind interfaces and injected into your view model. This way your view model knows nothing of these complex processes other than calling them via interface contracts. So your command fires and your view model provides orchestration, your service provides actual business calculations and an updated model would be produced representing the new state of the system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM