lundi 19 octobre 2015

Consultation about the best design for MVVM

little question. I'm progrraming in MVVM design pattern (C#). the View is an Excel add-in, and I want to run from the View_Model a method that found in the View. I thought about 2 ways:

  1. Hold in the View Model a pointer to the View (the pointer type is an interface that the View and the View_Model inherit from, otherwise I would get a circular independence because the View hold the View_Model and the View_Model hold the View), and then run the method directly from him.
  2. Create an event in the View_Model and sign the method in the View to that event in the View_Model pointer which I already have in the View, and raise the event when I want to run this method.

Somehow, way number 2 feel little like screaming in the street to only one man instead off go straight and talk to him normally. On the other hand, the advantage in way number 2, is that in the future if I would have other method that relate to this operation I could just sign them to that event and not call them specially.

what would you do?

Aucun commentaire:

Enregistrer un commentaire