jeudi 16 mai 2019

(MVVM) View Model per View or per Model?

:)

I’ve watched and read lots of MVVM materials during the past few weeks and there seems to be a major difference which everybody does in one way or another but doesn’t elaborate upon. Do we create a ViewModel per View or per Model?

There’s a question for it, but I don’t think its answered thoroughly. So..

Let’s use a Recipes app for example where we have three different views: RecipesViewController, RecipeViewController and RecipeCell. I think that the correct way to implement MVVM is to create one ViewModel per view instead of creating a RecipeModel and sharing it across them.

This example may be basic enough and we may prefer one ViewModel, but it’s not correct, is it? And if both are acceptable, can someone explain the differences, drawbacks & benefits? And if we have a networking layer, only the ViewModel should communicate with it, right?

Thank you.

Aucun commentaire:

Enregistrer un commentaire