How do you communicate between presenter and view in MVP scheme?

六眼飞鱼酱① 提交于 2019-12-25 05:12:00

问题


Basically there is two options as I know.

The first is view expose notifications events which a presenter should be subscribed to. When user clicks on some button on the view, view just triggers some event, notifies that something is changed.

The second is just use an observer pattern and let the presenter interfere some contract. Let it be an interface with methods like events I told you above. An presenter-observer should be attached to the view.

As Jeremy Miller in his legendary "Build your own CAB series" blog posts said, it's better for him to use the second option.

What's your opinion on this topic? How do you tie presenter and view in your projects? What's advantages or disadvantages for every options?

Let make some poll here. I think it would be useful. Thanks in advance!


In order to respond to Peter Ritchie's answer.

My issue is that my inexperience and I should rely on somebody's opinion to make a decision and choose a way that seems right to me.

The drawback with interfaces is that you have specific coupling. The view is coupled to an interface and something has to implement that interface

But on the other hand, is not events serves like a some contract (like an interface do)? It tied presenter to the view as it should react over that events.


回答1:


Observer can be a bit tedious. If you have several controls that produce events or several events, then you have to wire them up one at a time. Whereas if you use an interface, it's all in one place and you get type-safety and compile errors if you forget to implement a specific member of the interface. The drawback with interfaces is that you have specific coupling. The view is coupled to an interface and something has to implement that interface. you can use interface segregation to limit the interface coupling to one specific class; but, that adds a certain level of complexity.

There's no one right answer for this; is there some criteria you can offer to help with your decision?



来源:https://stackoverflow.com/questions/10561233/how-do-you-communicate-between-presenter-and-view-in-mvp-scheme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!