使用MVP模式进行设计 [英] Design using MVP pattern

查看:116
本文介绍了使用MVP模式进行设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试使用MVP模式实现一个站点(读取/更新/删除操作站点).还尝试保持表示层UI不可知(即表示层应与Web客户端/Windows客户端一起使用).
现在我有一个包含30个字段/属性的域对象,并且所有这些字段都可以在UI中进行编辑(视图).

我想将任何字段的更改推广到Presentation层.我唯一想到的解决方案是定义30个事件!!!在视图"中表示视图",在Presentation层中使用30个处理程序,或者在表示层中为视图中的30个事件处理程序定义30个setter方法.

对此设计不满意.
任何人都可以给我提供一个方法吗?解决方案或对此的方向?

Hi,
I am trying to implement a site(Read/Update/Delete operations site) using MVP pattern. Also trying to keep the presentation layer UI agnostic(i.e. Presentation layer should work with a Web Client/Windows Client).
Now I have a domain object with around 30 fields/attributes and all of these fields are editable in the UI(View).

I want to propogate the change in any field to the Presentation layer. The only solution I can think of is to define 30 events!!! in the View and 30 handlers in the Presentation layer or define 30 setter methods in the presentation layer for the 30 event handlers in the view.

Am not comfortable with this design.
Can any one provide me a solution or a direction on this?

推荐答案

首先,为什么表示层应在两种不同的表示模型中工作?

您是说控制器?

我可以看到以下内容:

Model< shared>
Controller< shared>
视图-一个Web实例,一个Web表单实例

这对我来说更有意义.

我还假设您所做的更改不仅限于某些"字段,还包括属于某个对象的字段.

所以为什么不在控制器中保持原始对象状态:

Controller< T>其中T:class

T _state;

具有类型化的args,类似于:

public class TypedArgs< T> :EventArgs,其中T:class
{
public T Value {get;放; }
}

为您的视图创建接口:

公共接口IView< T>其中T:类
{
event EventHandler< TypedArgs< T>>;已更改;
}

然后可以使用视图中的新实体引发Changed,并具有控制器注册.只需将IView传递给控制器​​,就不必在乎它是用户控件还是Web窗体,并且在引发Changed时,它可以将e.Value与存储状态进行比较并确定要执行的操作.

First, why should the presentation layer work in two different presentation models?

You mean the controller?

I can see this:

Model <shared>
Controller <shared>
View - one instance for web, one instance for web form

That makes more sense to me.

I''m also assuming your changes are to "something" not just random fields, but fields that belong to an object.

So why not maintain the original object state in the controller:

Controller<T> where T: class

T _state;

Have a typed args, something like:

public class TypedArgs<T> : EventArgs where T: class
{
public T Value { get; set; }
}

Create an interface for your views:

public interface IView<T> where T: class
{
event EventHandler<TypedArgs<T>> Changed;
}

then you can raise Changed with the new entity in the view, and have the controller register. Just pass in IView to the controller so it doesn''t care if it''s a user control or a web form, and when Changed is raised, it can compare e.Value to the stored state and decide what to do.


这篇关于使用MVP模式进行设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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