DAL/BLL 和客户端/服务器:客户端应该使用 BLL 还是 DAL 对象进行演示?或者可能是另一层(数据传输对象?) [英] DAL/BLL and Client/Server: Should the client use BLL or DAL objects for presentation? Or maybe another layer (data transfer object?)

查看:18
本文介绍了DAL/BLL 和客户端/服务器:客户端应该使用 BLL 还是 DAL 对象进行演示?或者可能是另一层(数据传输对象?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个客户端/服务器系统.服务器采用 DAL/BLL 设计.客户端负责呈现数据对象并提供对话框和向导以允许用户更新这些对象(即添加/编辑用户).

I'm writing a client/server system. The server has a DAL/BLL design. The client is responsible for presenting the data objects and providing dialogs and wizard to allow the user to update these objects (i.e. adding/editing a user).

最初我想我只是让 DAL 对象有一个通用的数据提供者对象,这样它们就可以被客户端和服务器使用.例如,当服务器正在使用数据对象时,数据库是数据提供者;当客户端使用数据对象时,服务器是数据提供者.

Initially I thought I'll just make the DAL objects have a universal data provider object so they can be used by the client as well as the server. For instance, when the data object is being used by the server, the database is the data provider; when the data object is being used by the client, the server is the data provider.

所以一个对象在表现层被改变,例如一个用户":user->setName("Fred"),然后像这样提交它 user->commit(),commit方法调用数据提供者的commit 方法,然后对对象进行编码并将其发送到服务器.然后服务器用业务层对象装饰"它并从那里继续.

So an object gets changed at the presentation layer, for example a "user": user->setName("Fred"), and then commits it like this user->commit(), the commit method calls the data provider's commit method, which then encodes the object and sends it to the server. The server then "decorates" it with the business layer object and carries on from there.

我目前将此作为原型工作,在共享项目中定义了 DAL 对象,该项目由客户端和服务器使用.然后服务器注入它的数据提供者(使用数据库),客户端注入一个使用服务器的数据提供者.

I currently have this working as a prototype, with the DAL objects defined in a shared project that gets used by both the client and the server. The server then injects it's data provider (which uses the database), and the client injects a data provider that uses the server.

我想知道这是否是一种合理的方法?我一直想知道我是否需要另一个层而不是将 DAL 对象直接暴露给客户端.也许是数据传输对象层,它会给我 3 层:数据访问对象、业务逻辑对象和数据传输对象.

I'm wondering if this seems like a reasonable approach? I keep wondering if I need another layer rather than having the DAL objects exposed directly to the client. Maybe a data tranfer object layer, which would give me 3 layers: Data access objects, business logic objects, and data transfer objects.

谢谢.

推荐答案

暴露内部对象"(如使用/返回的对象)购买 DAL 并不是一个好主意.最好对客户端隐藏所有内部对象,并拥有一组完整的对象用于客户端-服务器通信.将一个对象转换为另一个对象可能需要一些额外的工作,但在服务器和客户端不一起升级的情况下会使系统升级更加容易.

It is not a good idea exposing 'inner objects' like objects used/returned buy the DAL. Better keep all inner objects hidden from the client and have a complete set of objects for client-server communication. It might be some extra work converting one object to another but will make upgrading the system much easier in case server and client don't upgrade together.

这篇关于DAL/BLL 和客户端/服务器:客户端应该使用 BLL 还是 DAL 对象进行演示?或者可能是另一层(数据传输对象?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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