MVP和多个用户控件 [英] MVP and multiple User Controls

查看:108
本文介绍了MVP和多个用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用MVP模式,我运行到一个设计问题。我正在开发,将有几个用户控件的应用程序。该用户控件本身无关彼此,仅占实际模型的一个子集。从我读过的东西,人们往往会说,你应该使用每个视图一个演示。这似乎是有道理的,但如果我有30个用户控件,我真的希望30演示?在另一面,如果我有1 Presenter和1查看代表了整个应用程序的说法,那么我将有臃肿的查看和演示接口。然后,每个视图必须实现什么都没有用它做的方法。我的问题是,是否有更好的方法来处理多个用户控件,或者我应该只是创造1演示了每个View?

I’m trying to use the MVP pattern and I’m running into a design problem. I’m developing an application that will have several UserControls. The UserControls themselves have nothing to do with one another and only represent a subset of the actual model. From what I’ve read, people tend to say you should use one Presenter per View. This seems to make sense, but if I have 30 UserControls, do I really want 30 Presenters? On the flip side, if I have 1 Presenter and 1 View that represent the entire "application" view, then I’ll have bloated View and Presenter interfaces. Then each View would have to implement methods that have nothing to do with it. My question is, is there a better way to handle multiple UserControls, or should I just create 1 Presenter for each View?

推荐答案

它将使更多的意义组在一个对象相关的代码。因此,在这种情况下,如果意见是相关代码的特定的分组,则演示者也将模仿这些分组。这对于在一个对象的不同意见将组无关的代码全球主持人。这肯定会膨胀为演示接口为好。查看单一职责原则

It would make more sense to group the code that is related in one object. So, in this case, if the views are specific groupings of related code, then the presenter would also mimic these groupings. To have a "global" presenter for different views would group unrelated code in one object. It would definitely bloat the interface for the presenter as well. Check out the single responsibility principle.

现在,你可以有一个演示Manager类或许可以给你访问的每个主持人接口的像接口分离原则的状态,方法是继承(有实现了许多主持人interfaces..which一种违反单负有责任的全球混凝土主持人)或聚集(具有独立的主持人为每个接口和获取功能...因而全局接口将所述的get函数)或两者的组合(全球演示作为一个适配器的几分)。

Now, you could have one Presenter Manager class perhaps that could give you access to each presenter interface, like the Interface Segregation Principle states, by either inheritance (have a global concrete presenter that implements many presenter interfaces..which kind of violates the single responsibilty) or aggregation (having individual presenters for each interface and get functions...thus the global interface would the the get functions) or a combination of both (global presenter being somewhat of an adapter).

我认为最好的解决办法,虽然也只是有30个不同的主持人。

I think the best solution though would just to have 30 different presenters.

这篇关于MVP和多个用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆