mardi 25 août 2015

MVP Pattern: How does the model ask for a View?

I'm having troubles while implementing the MVP pattern. To explain it easy:

I have a WinForm (the View) who implements an interface (its corresponding IView). I have also a the presenter and, at last, the model.

But at the beginning, there was no IView, nor Presenter nor Model. There was one huge View that made everything. And so refactoring began...

Everything went fine, almost perfect. But now, I met this situation and a question about design came to me:

I found the view has a method which takes over of an event. This method is very big and have lots of logic. So I just put all the method in the presenter to free the view of logic. Everything was quite ok.

But then, I wanted to free the presenter from this logic and charge the model with it... because that logic were business rules!

I started doing this, and then I realized something: in some places this logic was asking me to instantiate other WinForms.

Now comes the question: If the presenter doesn't know anything about business rules, he shouldn't know when to instantiate a WinForm or not. So who knows? The Model, of course. But...

  1. How can the model tell somebody which View (and when) to instantiate?
  2. Who should be this "somebody"?
  3. Am I alright when I say the presenter should not know when and which view to create? Only tell the IView implementation to do it, only if somebody asks for it (maybe the model).

Thank you all!

Aucun commentaire:

Enregistrer un commentaire