您如何在演示者和视图之间进行沟通

您如何在演示者和视图之间进行沟通

本文介绍了在MVP方案中,您如何在演示者和视图之间进行沟通?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我知道有两个选项。

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.

正如杰里米·米勒(Jeremy Miller)在传奇的说,最好使用第二个选择。

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!

为了回应彼得·里奇的回答。

我的问题是我的缺乏经验,我应该依靠某人的意见作出决定,并选择一种似乎适合我的方式。

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.

但另一方面,事件不是像一些合同(像界面一样)?它将主持人视为观点,因为它应该对事件作出反应。

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.

推荐答案

观察者可能有点乏味。如果您有几个控件可以生成事件或多个事件,那么您必须一次连接一个。而如果您使用接口,则它们位于一个地方,如果您忘记实现该接口的特定成员,则会得到类型安全性并编译错误。接口的缺点是具有特定的耦合。该视图耦合到一个接口,某些东西必须实现该接口。您可以使用界面隔离来限制与一个特定类的连接;但是,这增加了一定程度的复杂性。

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?

这篇关于在MVP方案中,您如何在演示者和视图之间进行沟通?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 15:27