Transfer 对象和 Domain 对象之间的区别
您能简单地解释一下 Transfer 对象和 Domain 对象之间的区别吗?如果你能给出一个 Java 例子,那就太好了..
Could you please explain the difference between Transfer objects and Domain objects in simple terms ? And if u could give a Java example, that would be great..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果使用贫乏的数据模型(即您的域对象没有任何逻辑),DTO 和域对象可以是同一个对象。
相关:http://techblog.bozho.net/?p=427
If using anemic data model (i.e. your domain objects don't have any logic), DTO and domain object can be the same object.
Related: http://techblog.bozho.net/?p=427
数据传输对象(DTO)用于在应用程序的不同部分(例如不同层)或不同应用程序之间交换数据。
域对象(DO)(以及派生它们的类)实现业务逻辑,因此它们仅位于业务逻辑层/域中(即使术语是不同的)。
因为 DO 实现业务逻辑,所以它们可能很复杂,并且可以包括方法、事件等。
关于 DTO 的另一点
根据 Martin Fowler 学派的观点,DTO 是多个对象的组合(每个对象都是大多数人通常所说的 DTO);其基本原理是,在某些情况下,以较低的频率发送较大的数据包会更便宜(而不是“喋喋不休”并通过网络不断发送许多小数据包)。
因此,大多数人将 DTO 视为单个对象,Martin F 表示 DTO 只是一个包含几个离散(可能不相关)对象的“信封”。在我看来,这不是一个大问题 - 大多数人认为 DTO 是按照我在这个答案顶部的定义(或接近它的东西)。
A Data-Transfer-Object (DTO) is used to exchange data between different parts of an application (such as different layers), or different applications.
Domain Objects (DO) (and the classes from which they are derived) implement business logic, as such they are only located in the Business logic layer / Domain (the essential meaning is the same even if the terms are different).
Because DO's implement business logic they can be complex, and can include methods, events and so on.
One more point about DTOs
According to the Martin Fowler school of thought a DTO is a combination of several objects (each of which would be what most people would commonly call a DTO); the rationale is that in situations it's less expensive to send larger packages of data less frequently (as opposed to being "chatty" and sending many small packages constantly across the wire).
So where most people would view a DTO as a single object Martin F is saying a DTO is simply an "envelop" that contains several discrete (and possibly unrelated) objects. Not a big issue IMO - most people take the view that a DTO is as per my definition at the top of this answer (or something close to it).
由于其使用的性质,传输对象通常是可序列化的,如果调用是远程的并且在 JVM 之间,或者它们将以促进序列化的方式使用(例如有状态会话 Bean),则这一点尤其相关。为此,传输对象必须易于接受这种“处理”,即传输对象实现可序列化。
领域对象则不然。领域对象可能包含行为,但 DTO 只是一种传输介质。
Transfer objects are often serializable due to the nature of its use, this is especially pertinent if the calls are remote and between JVM, or they will be used in a way that promotes serialization, such as stateful session beans. For this purpose, transfer objects must be susceptible to such "treatment", I.e. Transfer objects implement serializable.
The reverse may not be said of domain objects. Domain objects may contain behavior, however DTO are merely a transportation medium.
业务角度的领域对象,它是整个领域和流程的活动的参与者或主体,DTO是数据对象,它与忠实反映数据库对象的数据bean不同(尤其是在ORM架构中)
DTO可以进行数据聚合、转换、组合以满足表示或某些数据操作的需要,它没有主题,但域对象根据其域级别定义有主题
Domain object in business perspective, it is actor or subject of the activity with whole domain and flows, DTO is the data object which is not the same as data bean that faithfully to reflect database objects (especially at ORM architecture)
DTO can has data aggregation, transform , combination to satisfy the representation or some data munipulate needs , it is no subject , but Domain object has subject base on their domain level defination