0

I'm having quite a bit of trouble trying to understand this pattern. At work we are implementing MVP with passive views. We are using WinForms.

  • So we have a View (which is a windows form), which implements an interface and has a presenter.
  • The presenter gets an instance of the interface which the view implements, and manages the view throw the interface.
  • The presenter can see the model, and a manager.
  • The manager handles the database persistance of several models, but it does not add them manually, it uses a separate layer, called Data, so it tells that layer to persist data
  • The data layer then persists the data to the database, using Entity Framework

Say we have a view of Clients, which reperesents a Model Clients and we have a table in our database called Clients. Clients can have name, and city.

We also have a view for Cities, which is a simple add, edit and remove, it also represents a model City, and a table City.

Now in our view of Clients, we want to let the user add a new city, so in the view, we open another view, the Cities view, the user then creates a new city.

From the Clients view, I want to see what City the user added, how is that possible? Shall the view return something?

(I want to have it in memory, not persist anything to the database when adding a city, I just want the model of the city)

I think returning a model and viewing models from the view is not MVP. How can I do it then?

gosukiwi
  • 1,569
  • 1
  • 27
  • 44
  • Im assuming your ViewModel fires appropriate events to update the UI when it's data changes? – Tejs Apr 25 '12 at 17:23
  • What do you mean by ViewModel? – gosukiwi Apr 25 '12 at 17:29
  • It sounds like your interface is the ViewModel. When you set something on your interface, the UI updates, yes? – Tejs Apr 25 '12 at 17:29
  • Yes, it does. So the Cities view should have access to the Clients interface? – gosukiwi Apr 25 '12 at 17:30
  • It sounds like the Form should simply expose the interface element is has as a property, and then your other forms can simply talk to that interface to set items. – Tejs Apr 25 '12 at 17:31

1 Answers1

0

One view opening up another is perfectly reasonable, but I personally don't favour the view returning a value to be used by the caller. What if other views needed to have access to this new city?

See my answer here: MVP Communication between presenters? for an example of using pub/sub to achieve your goal.

Community
  • 1
  • 1
Steven P
  • 1,956
  • 1
  • 16
  • 17