How does MVVM really work? What are the responsibilities of ViewModel and Model?
I've been implementing a project with MVVM
pattern for some time, but now some questions have come up about the pattern.
Where to implement the INotifyPropertyChanged
interface? I've learned to implement it in ViewModel
, but I see many examples implementing direct in Model
.
Another question would be where to implement a code of the type in the example, in viewModel
or Model
.
I would for example set the value of a int
and save it in Backend
shortly after.
public class ModelExample
{
int items {get; set;}
}
public class ViewModelExample
{
ModelExample modelExemplo {get; set;}
ViewModelExample(ModelExample modelObject)
{
modelExemplo = modelObject;
}
//Implemento um metódo desse tipo na ViewModel ou na Model?
public async Task Adicionar(){
modelExemplo.Items++;
//Salva no Backend do Azure (para ilustar o exemplo)
AzureMobileServices.Instance.SaveDataAsync(modelExemplo);
}
}