mercredi 28 juin 2017

MVVM : interactively adding new model instance

I have a program designed using MVVM approach: there is some data, stored in DB with Model classes encapsulating this data and all the business logic, there is a set of Views (UI controls) and there are ViewModels, that serve as in-between, getting data from models and passing it UI for presenting and working with.

All is working fine. Now I have a new requirement: to create a new instance of data interactively. So I should have a kind of dialog with its fields following strictly my model's inner structure. The user fills in the fields, presses Apply and new instance of a model is created.

The problem is: in doing so I am interfering with the main MVVM principle: now my views are intimately acquainted with my models. Obviously, I can use my ViewModel, to pass all the fields to it one by one, and make it responsible for a new model instance creation. However there are tens of fields and it hardly looks a better solution, it is still a very tight coupling.

I work with C++, not C#

Any advice?

Aucun commentaire:

Enregistrer un commentaire