简体   繁体   English

模型视图呈现器和大型对象的传输

[英]Model-View-Presenter and Transferring Large Objects

I have traditionally implemented a Model-View-Presenter [Passive View] like so: 传统上,我已经实现了Model-View-Presenter [Passive View],如下所示:

interface IView
{
string Title {set;}
}

class frmTextBox : Form, IView
{
...
public string Title
{
set { this.txtTitle.Text = value; }
}
...
}


class frmLabel : Form, IView
{
...
public string Title
{
set { this.lblTitle.Text = value; }
}
...
}

class Presenter
{
private IView view;
...
public void UpdateTitle
{
this.view.Title = "A Good Title";
}
...
}

and I have traditionally only used primitive types in the IView interface ( int , string , bool ) because I have always understood that you need to use primitive types only in the View. 传统上我只在IView接口中使用基本类型( intstringbool ),因为我一直都知道您只需要在View中使用基本类型。 In a Repository (such as NHibernate ), if I want to display a list of items in a DataGridView , I have to pass a generic collection ( IList<T> ) from the Model to the Presenter. 在存储库(例如NHibernate )中,如果要在DataGridView显示项目列表,则必须将通用集合( IList<T> )从模型传递给Presenter。 Does that violate the rule behind views as consisting only of primitive types or would this architecturally be OK? 这是否违反了仅由基本类型组成的视图背后的规则,还是在架构上可以做到?

Even if I had a Data Transfer Object (DTO), that would be more of a supervising controller rather than passive view style I am trying to implement. 即使我有一个数据传输对象(DTO),也更像是一个监督控制器,而不是我尝试实现的被动视图样式。

Thoughts?? 思考?

Wow maybe I've been missing out on a lot. 哇,也许我错过了很多东西。 I've never seen views as being limited to only displaying primitive types. 我从未见过将视图限制为仅显示原始类型。

I'd be interested to know why this restriction is used and what the benefit of it is? 我想知道为什么使用此限制,它的好处是什么? That's not to say that "IMO it's totally wrong", but I'm curious as to its benefits. 这并不是说“ IMO这是完全错误的”,但我对其好处感到好奇。 My belief is that computers are sufficiently powerful now that unless you are targetting a specific performance specification the cost of a developer hammering away to fit some guideline would be an expensive use of resources. 我的信念是,计算机现在已经足够强大,除非您以特定的性能指标为目标,否则开发人员不惜重金以适应某些准则的成本将是对资源的昂贵使用。

Not that it's any endorsement per se. 并不是说这本身就是任何认可。 but all the MVC articles I've seen have been happily banding around classes between the view and controller. 但是我见过的所有MVC文章都在视图和控制器之间的类周围很愉快。 Since MVP is just a different form of MVC I'd say if it's not a problem with MVC should it be with MVP? 由于MVP只是MVC的另一种形式,我想说如果MVC没问题,那么MVP应该吗?

Patterns exist to help you design your solution based on others' experiences. 存在模式可以帮助您根据他人的经验设计解决方案。

They are nothing more than formalized templates. 它们不过是形式化的模板。

Use whatever structure makes you more productive, even if it doesn't fit an arbitrary definition perfectly. 使用任何结构都可以提高工作效率,即使它不能完美地适合任意定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM