ViewModels represent data that will be displayed in view . Your goal is to put together a model that will make it easier to use when you present them, probably each in a different screen control. They serve both to not use everything in the model , and to merge data from multiple models . You can even get data that is not even in the models used. It is common that they even have formatted data for the presentation, as opposed to the model .
Then you should ask yourself what is best suited for your presentation, have the data placed directly on the object or have an indirection for them in another object? So both can work according to need. The indirection can be for another ViewModel or for a model directly.
Will it help you have the data of PersonalData
and Address
on ManagerViewModel
properties? Or is it enough to have something that indicates where that data is and the view is able to turn out well? Remember that views should be very simple and should have minimal processing.
Eventually you can have property indirection and have auxiliary methods that help you access the data within that property.
If you are using ViewModels because someone said it is good, you are using it for the wrong reasons. Use if it makes your life easier. If it is to reproduce what is in the models , then it has no real function for your code.
ViewModels can be automatically updated by the framework for annotations or events placed on it, or can be created by the controller . It depends on the need. They can upgrade the templates as well.
The important thing is to understand that ViewModel is a template for the view. It works to meet the needs of view , that's all that matters.
Do you know the view of SQL? That's basically it (despite the confusion of names). You create a logical model easier to consume in a specific situation.
A deepening the theme .