实现服务层方法的指南
我们正在开发一个三层应用程序,其中表示层与服务层通信,服务层又与业务层通信。业务层可以访问数据库。目前我们已经实现了业务层来保存表的CRUD操作。 我们对组织服务层和业务层的方法有一些疑问。
首先,服务层的方法应该如何分组?我们是否应该基于页面对方法进行分组,其中页面所需的所有数据均由服务的方法提供。还是应该通过多次服务调用来获取页面数据?
另一个问题是业务层方法的组织,似乎对于服务层的任何方法我们都必须在业务层实现相应的方法。如果我们按照这个逻辑,服务层的方法将像虚拟的一样,只负责授权和验证。例如:当获取来自两个表的联接的数据时,我们应该在服务层获取两个表,然后在服务层上进行联接,还是应该在业务层上有一个执行相同操作的函数。从本质上减少了服务层和业务层之间的数据传输。
We are developing an 3-tier application where presentation layer communicates with service layer, which in turn communicates with the business layer. The business layer has access to database. Currently we have implemented business layer to hold CRUD operations for tables.
We have a couple of doubts regarding organizing the methods in service layer and business layer.
Firstly, how should the methods at service layer be grouped? Should we group the methods based on a page basis, where in all the data a page needs are provided by a method of a service. Or should we fetch the page data by multiple service calls ?
The other concern is about organizing methods at the business layer, it seems that for any method at the service layer we have to implement a corresponding method at business layer. If we go by this logic the methods at service layer would be acting like dummies, and only taking care of authorization and validation. For ex: when fetching a data that comes from join of two table, should we fetch the two tables on the service layer and then do the join on the service layer or should we have a function on business layer which does the same thing. Essentially reducing the data transfer between service layer and business layer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请查看 DTO 模式。使用 DTO 模式 - 您可以最大限度地减少对后端服务的调用次数。并且给定的 DTO 可以映射到多个 BO。您需要根据填充 UI 的数据要求设计 DTO。
Please have a look at the DTO pattern. With the DTO pattern - you minimize the number of calls to the backend service. And given DTO can map in to multiple BOs. You need to design DTOs based on your data requirement to populate the UI.
看来我想要的是遵循 REST 架构。这意味着我应该保持服务层和表示层之间的接口统一。
服务层负责授权,并将所有调用委托给业务层。在业务层,我们保留 DTO,在将它们发送到 SL 之前,将其序列化为 XML、JSON 或其他内容。
真正对我有帮助的是阅读 REST 文章并详细探索它们。
Well it looks like what i wanted was to follow the REST architecture. Which means that i should keep the interfaces uniforms between service layer and presentation layer.
The service layer takes care of authorization and just delegates all the calls to the business layer. At business layer we keep the DTOs which are serialized to XML, JSON or whatever before sending them to SL.
What really helped me was going through REST articles and exploring them in detail.