Value对象应包含多少业务逻辑? [英] How much business logic should Value objects contain?

查看:130
本文介绍了Value对象应包含多少业务逻辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尊重的一位导师认为,简单的bean浪费时间 - 值对象必须包含一些有用的业务逻辑。

One mentor I respect suggests that a simple bean is a waste of time - that value objects 'MUST' contain some business logic to be useful.

另一个人说这样的代码难以维护,并且所有业务逻辑都必须外部化。

Another says such code is difficult to maintain and that all business logic must be externalized.

我意识到这个问题是主观的。无论如何要求 - 想要从更多角度了解答案。

I realize this question is subjective. Asking anyway - want to know answers from more perspectives.

推荐答案

你最好打电话给他们传输对象数据传输对象(DTO)

You should better call them Transfer Objects or Data transfer objects (DTO).

之前这个相同的j2ee模式被称为值对象,但是他们更改了名称,因为它与此混淆了

Earlier this same j2ee pattern was called 'Value object' but they changed the name because it was confused with this

http:/ /dddcommunity.org/discussion/messageboardarchive/ValueObjects.html

为了回答你的问题,我只会将最小的逻辑放到我的DTO中,这是必需的逻辑显示原因。

To answer your question, I would only put minimal logic to my DTOs, logic that is required for display reasons.

更好的是,如果我们谈论基于数据库的Web应用程序,我会超越核心j2ee模式并使用 Hibernate Java Persistence API 用于创建支持延迟加载关系的域模型,并在视图中使用它。

Even better, if we are talking about a database based web application, I would go beyond the core j2ee patterns and use Hibernate or the Java Persistence API to create a domain model that supports lazy loading of relations and use this in the view.

请参阅在视图中打开会话

这样,您就不必编写一组DTO,并且您可以在视图/控制器等中使用所有业务逻辑。

In this way, you don't have to program a set of DTOs and you have all the business logic available to use in your views/controllers etc.

这篇关于Value对象应包含多少业务逻辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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