In a wpf application, Whats the responsibility of the viewmodel? can he manage everything or only represent the view and send messages/event to the business layer and get information from it?
A ViewModel object provides the data for a specific UI component, such as a fragment or activity, and contains data-handling business logic to communicate with the model.
View Model: It encapsulates the presentation logic required to support a use case or user task in the application. The view model is testable independently of the view and the model. The view model typically does not directly reference the view. It implements properties and commands to which the view can data bind.
In MVVM, the business logic is built into the Model. The ViewModel is there to bridge between the View and the Model, so it's logic only pertains to driving the display and updating the model from user interactions with the View.
The ViewModel class is designed to store and manage UI-related data in a lifecycle conscious way. The ViewModel class allows data to survive configuration changes such as screen rotations.
Short answer, Yes.
Longer answer ...
The main aims of the Model-View-ViewModel (MVVM) pattern are:
The MVVM pattern also provides separation of concerns between view logic and business logic in the same way that the MVC and their UI pattern do. However, the 2 points above are what really define the MVVM pattern.
Now, thinking about where you locate your business logic. If you place it in your ViewModel, are #1 & #2 above still valid? Yes. If you place it in a separate layer, are #1 and #2 still valid? Yes.
Therefore, in both cases you are still achieving the two main goals of MVVM. Which route you take really depends on the complexity of your application, and the number of developers working on it. As both these factors increase, you will benefit from having 3 layers ... or more!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With