MVP事件或财产财产、事件、MVP

2023-09-04 02:32:25 作者:你我终不遇

我使用的是在Windows窗体应用程序中的MVP模式。我需要改变视图中的一个单选按钮。我可以通过暴露在视图布尔属性做到这一点,但我应该用事件来操作视图,而不是?

I'm using the MVP pattern in a windows form app. I need to change a radio button on the view. I can do this by exposing a Boolean property on the view, but should I be using events to manipulate the view instead?

推荐答案

这是纯洁的事VS务实......和一点个人风格。要不要紧......事件比正常的方法,但更多的去耦只是更多的工作。 个人

It's a matter of purity vs being pragmatic... and a bit of personal style. Shouldn't matter... events are just more work than normal methods but more decoupled. Personally

我想保持脱钩的意见或不知道的presenters的,因此欣赏到presenter通过提高事件的通信。这消除了需要为视图具有参考presenter。保留意见薄又哑。 另一方面的presenter有一个成员参考视图(与模型)通常。因此它可以通过使法交谈的视图经由接口调用的(许可证视图只要它们符合IVIEW接口取代)。例如在你的情况,Set_X_Option(eOptionEnum)将利用iView接口,其中presenter可以然后调用适当的成员。 I like to keep views decoupled or unaware of the presenters, hence Views communicate to the presenter by raising events. This eliminates the need for the view to have a reference to the presenter. Keep Views thin and dumb. The presenter on the other hand has a member reference to the view (and the model) usually. Hence it can talk to the view by making method calls via an interface (permits views to be substituted as long as they conform to the IView interface). e.g. In your case, Set_X_Option(eOptionEnum) would be a member of the IView Interface, which the presenter can then invoke appropriately.

不过,你可以删除此iView依赖(presenter有参考的iView中,需要被实例化,并插入),以及通过使用事件左右逢源......然而,我发现它的工作太多了。上述方案还从未失败过我......还没有。

However you could remove this IView dependency (presenter has reference to an IView, that needs to be instantiated and plugged in) as well by using events both ways... however I find that its too much work. The above scheme has never failed me... yet.