简体   繁体   中英

Communicate between views

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM