Can I instantiate a model inside the viewmodel?
Suppose in order to use the model's methods in the viewmodel.
Does it break the mvvm pattern?
And, if possible, an example, please, how to implement it correctly
2 answers
Can. In the simplest case, this is exactly what needs to be done. V "requests" a certain interface from the VM, and the VM implements this interface using the tools provided by M. Under the interface, I accept a set of properties and commands that V wants to provide to the end user. In more complex cases, if you have multiple models, the VM may receive an instance of M as a constructor parameter, for example.
|
Can. And create, and use. According to MVVM, a VM has the right to know about and manage M.
For example - look, for example, here .
|