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

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

问题描述

我正在尝试使用MVP模式,并遇到设计问题。我正在开发一个将有几个UserControls的应用程序。 UserControls本身与彼此无关,仅代表实际模型的一个子集。从我所看到的,人们往往会说你应该使用每个视图的一个Presenter。这似乎是有道理的,但如果我有30个UserControls,我真的想要30个演示者吗?另一方面,如果我有一个代表整个应用程序视图的Presenter和1 View,那么我将会有一个blo肿的View和Presenter界面。那么每个View都必须实现与它无关的方法。我的问题是,是否有更好的方式处理多个UserControls,或者我应该为每个视图创建1个Presenter?

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.

现在,您可以有一个Presenter Manager类,可能会让您访问每个演示者界面,像界面隔离原则一样,通过继承(具有实现许多演示者接口的全球具体演示者),哪种违反单一责任)或聚合(每个接口具有单独的演示者,并获得功能...因此全局接口将是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天全站免登陆