业务逻辑属于服务层吗?

发布于 2024-08-25 05:35:46 字数 255 浏览 3 评论 0原文

我有一组类,即数据传输对象、服务实现对象和数据访问对象。我目前在服务实现对象中有业务逻辑;它使用 dao 获取数据来填充运回客户端/gui 代码的 dto。

问题是我无法创建服务实现对象的轻量级 junit 测试(它是一个 servlet);我认为业务逻辑应该在其他地方,但我唯一能想到的就是将业务逻辑放在 dao 中或放在 dao 和服务实现之间的另一层中。

还有其他选择吗,或者我的想法是错误的?

这是一个 GWT/App Engine 项目。

I've got a set of classes, namely, a data transfer object, a service implementation object, and a data access object. I currently have business logic in the service implementation object; it uses the dao to get data to populate the dto that is shipped back to the client/gui code.

The issue is that I can't create a lightweight junit test of the service implementation object(it's a servlet); I think the business logic should be elsewhere, but the only thing I can think of is putting business logic in the dao or in yet another layer that goes between the dao and the service implementation.

Are there other options, or am I thinking about this the wrong way?

It's a GWT/App Engine project.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

同展鸳鸯锦 2024-09-01 05:35:46

我不明白为什么你不能对 servlet 进行单元测试,例如按照这个问题 (还有其他类似主题)——你能解释一下吗?

编辑:如果没有特殊原因,我建议您应该在服务层(它似乎属于的位置)中进行业务逻辑并在那里对其进行单元测试 - 我刚刚在SO问题中建议的方法例如,引用似乎相当轻量(尽管我没有专门测试它们)。

I don't understand why you can't unit-test the servlet, e.g. as per this SO question (there are others on similar themes) -- can you please explain?

Edit: if there's no special reason, I suggest you should the business logic in the service layer (where it seems to belong) and unit-test it there -- the approaches suggested in the SO question I just quoted, for example, seem reasonably lightweight (though I didn't test them specifically).

凡间太子 2024-09-01 05:35:46

您可以将业务逻辑放在它自己的 jar 文件中,并独立于与 Web(servlet)的集成来测试该组件。servlet

只是一个协议,它不是您的业务逻辑,更多的是一个集成点。

通过胖客户端暴露相同的业务逻辑一定很容易想象。
同样在这种情况下,您不应隐藏按钮或链接下的业务逻辑。

还有一点需要注意:您可能想研究一下 MVC 框架;支柱。您的模型将保存业务逻辑。

希望这有帮助。

You can put your business logic in it's own jar file and test this component independently from the integration with the web (servlet)

The servlet is just a protocol, it is not your business logic, more an integration point.

It must be easy to imagine to expose your same business logic through a thick client.
Also in that case, you should not hide the business logic under buttons or links.

One more note: you might want to look into the MVC framework; struts. Your model will hold the business logic.

Hope this helps.

帅的被狗咬 2024-09-01 05:35:46

servlet 是控制器,将业务逻辑放在那里是一个很大的错误。

The servlet is the controller , it is a very big mistake, to put the business logic there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文