在 ntier 应用程序中传递数据 [英] passing data in an ntier application

查看:15
本文介绍了在 ntier 应用程序中传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将数据传递到 n 层应用程序中的层?我已经制定了 3 种不同的方法.

How do you pass data to layers in an n-tier application? I have mapped out 3 different methods.

A)通用 .net 对象通用数据表、哈希表、通用数据集、字符串、整数等...然后使用数据集填充发送到 UI 层的业务对象.

A) generic .net objects generic data tables, Hashtables, generic datasets, strings, ints etc... then using the datasets to fill your business objects which get sent to the UI layer.

替代文字 http://img11.imageshack.us/img11/460/generic.png

http://dabbleboard.com/draw65b=54eef6f1ac01f03c85919518f4a24e798e57e133i=26&c=54eef6f1ac01f03c85919518f4a24e798e57e133

Pro- 不需要额外的层Con- 必须在业务层使用通用数据集和表

Pro- No extra layers needed Con- Have to work with Generic datasets and tables in the business layer

B)使用其他层将引用的实体层.该层将包含强类型数据集或普通旧 C 对象.对象将主要是容器数据和很少的逻辑.这些将是发送到 UI 层的相同对象.

B) using an entities layer that the other layers would reference. This layer would contain either strongly typed datasets or Plain Old C Objects. The objects would be mostly container data and very little logic. these would be the same objects sent to the UI layer.

替代文字 http://img8.imageshack.us/img8/6454/entities.png

http://dabbleboard.com/165&c=d0c2b346894a96b12bd3867f630e474a2af098fai=6&c=d0c2b346894a96b12bd3867f630e474a2af098fa

Pro- 在所有层中使用相同的类Con- 向所有层添加对entities.dll 的引用

Pro- working with the same classes in all layers Con- adding a reference to entities.dll to all layers

C)使用数据访问层中定义的数据传输对象(仅限容器对象).然后使用这些对象来填充发送到 UI 层的业务对象.

C) use data transfer objects (conatiner objects only) defined in the DataAccess Layer. then using those objects to fill business objects which get sent to the UI layer.

替代文字 http://img43.imageshack.us/img43/1236/transferp.png

http://dabbleboard.com/draw5&iu16i=27&c=f886efa3f9d5eb4b45ddb02361c79cdcdaec0a9b

Pro- 业务层不必使用泛型类Con- 使用两种类型的对象,您必须将业务对象与传输对象结合起来

Pro- the business layer would not have to work with generic classes Con- working with two types of objects and you would have to hydrate the business objects with the transfer objects

我们在工作中进行了讨论,想了解社区的想法.我还添加了一个指向 Dabbbleboard 的链接.请复制和创建而不是编辑.
谢谢

We had a discussion at work and wanted to see what the community thought. I also added a link to the dabbleboard. please copy and create instead of editing.
Thanks

推荐答案

如果您使用 分层 方法,这意味着所有层(本质上)都在同一个进程空间中执行,因此没有编组/序列化,我会采用方法 B.为您的实体创建一个单独的模块,您的程序的所有方面都依赖于该模块,并与之结合.

If you're using a layered approach, meaning all layers are (essentially) executing in the same process space and there is therefore no marshalling/serialization, I'd go with approach B. Create a separate module for your entities upon which all aspects of your program depend, and couple to that.

但是,如果您使用的是分层方法,正如您的标题所暗示的那样,这意味着跨越了流程和/或网络边界,我建议您采用方法 C.您并不是真正地传递实例,而是传递副本,因此耦合到同一对象的任何好处,例如 MVC 方法的可观察选项,无论如何都会丢失.最好在每个层级定义数据 API,而不是尝试到处使用相同的类.

If, however, you're using a tiered approach as your title suggests, meaning there are process and/or network boundaries that are crossed, I'd suggest you go with approach C. You're not really passing instances around, you're passing copies, so any benefits you get to coupling to the same object, like observable options for, say, an MVC approach, are lost anyway. Better to define data APIs at every tier level than to try to use the same class all around.

这篇关于在 ntier 应用程序中传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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