DTO, VO, POJO, JavaBeans之间的区别?

时间:2021-04-15 17:37:07

Have seen some similar questions:

也遇到过类似的问题:

Can you also please tell me the contexts in which they are used? Or the purpose of them?

你能告诉我它们使用的上下文吗?或者他们的目的是什么?

6 个解决方案

#1


684  

JavaBeans

A JavaBean is a class that follows the JavaBeans conventions as defined by Sun. Wikipedia has a pretty good summary of what JavaBeans are:

JavaBean是遵循Sun定义的JavaBean约定的类。*对javabean有一个很好的总结:

JavaBeans are reusable software components for Java that can be manipulated visually in a builder tool. Practically, they are classes written in the Java programming language conforming to a particular convention. They are used to encapsulate many objects into a single object (the bean), so that they can be passed around as a single bean object instead of as multiple individual objects. A JavaBean is a Java Object that is serializable, has a nullary constructor, and allows access to properties using getter and setter methods.

JavaBeans是可重用的Java软件组件,可以在构建器工具中可视化地操作。实际上,它们是符合特定约定的Java编程语言编写的类。它们用于将许多对象封装到一个对象(bean)中,以便它们可以作为一个bean对象传递,而不是作为多个单独的对象。JavaBean是可序列化的Java对象,具有一个nullary构造函数,允许使用getter和setter方法访问属性。

In order to function as a JavaBean class, an object class must obey certain conventions about method naming, construction, and behavior. These conventions make it possible to have tools that can use, reuse, replace, and connect JavaBeans.

为了作为JavaBean类函数,对象类必须遵守关于方法命名、构造和行为的某些约定。这些约定使能够使用、重用、替换和连接javabean的工具成为可能。

The required conventions are:

所需的约定:

  • The class must have a public default constructor. This allows easy instantiation within editing and activation frameworks.
  • 类必须具有公共默认构造函数。这允许在编辑和激活框架中进行简单的实例化。
  • The class properties must be accessible using get, set, and other methods (so-called accessor methods and mutator methods), following a standard naming convention. This allows easy automated inspection and updating of bean state within frameworks, many of which include custom editors for various types of properties.
  • 必须使用get、set和其他方法(所谓的accessor方法和mutator方法)访问类属性,遵循标准的命名约定。这允许在框架内自动检查和更新bean状态,其中许多框架包括用于各种类型属性的自定义编辑器。
  • The class should be serializable. This allows applications and frameworks to reliably save, store, and restore the bean's state in a fashion that is independent of the VM and platform.
  • 类应该是可序列化的。这使得应用程序和框架能够可靠地保存、存储和恢复bean的状态,这种方式与VM和平台无关。

Because these requirements are largely expressed as conventions rather than by implementing interfaces, some developers view JavaBeans as Plain Old Java Objects that follow specific naming conventions.

由于这些需求主要以约定的形式表示,而不是通过实现接口来表示,因此一些开发人员将JavaBeans视为遵循特定命名约定的普通旧Java对象。

POJO

A Plain Old Java Object or POJO is a term initially introduced to designate a simple lightweight Java object, not implementing any javax.ejb interface, as opposed to heavyweight EJB 2.x (especially Entity Beans, Stateless Session Beans are not that bad IMO). Today, the term is used for any simple object with no extra stuff. Again, Wikipedia does a good job at defining POJO:

一个普通的旧Java对象或POJO是一种最初引入的术语,用来指定一个简单的轻量级Java对象,而不是实现任何javax。ejb接口,与重量级ejb 2相反。x(特别是实体bean、无状态会话bean在我看来并没有那么糟糕)。今天,这个术语用于任何没有额外内容的简单对象。*在定义POJO方面做得很好:

POJO is an acronym for Plain Old Java Object. The name is used to emphasize that the object in question is an ordinary Java Object, not a special object, and in particular not an Enterprise JavaBean (especially before EJB 3). The term was coined by Martin Fowler, Rebecca Parsons and Josh MacKenzie in September 2000:

POJO是普通Java对象的缩写。这个名称用来强调所讨论的对象是一个普通的Java对象,而不是一个特殊的对象,尤其是一个企业JavaBean(特别是在EJB 3之前)。

"We wondered why people were so against using regular objects in their systems and concluded that it was because simple objects lacked a fancy name. So we gave them one, and it's caught on very nicely."

“我们想知道为什么人们如此反对在他们的系统中使用常规对象,并得出结论,这是因为简单对象缺少一个花哨的名称。”所以我们给了他们一个,而且很好地抓住了。”

The term continues the pattern of older terms for technologies that do not use fancy new features, such as POTS (Plain Old Telephone Service) in telephony, and PODS (Plain Old Data Structures) that are defined in C++ but use only C language features, and POD (Plain Old Documentation) in Perl.

该术语延续了不使用花哨新特性的技术的旧术语模式,如电话中使用POTS(普通的旧电话服务)和POD(普通的旧数据结构),它们在c++中定义,但只使用C语言特性,在Perl中使用POD(普通的旧文档)。

The term has most likely gained widespread acceptance because of the need for a common and easily understood term that contrasts with complicated object frameworks. A JavaBean is a POJO that is serializable, has a no-argument constructor, and allows access to properties using getter and setter methods. An Enterprise JavaBean is not a single class but an entire component model (again, EJB 3 reduces the complexity of Enterprise JavaBeans).

与复杂的对象框架相比,这个术语很可能得到了广泛的接受,因为它需要一个通用且容易理解的术语。JavaBean是可序列化的POJO,具有无参数构造函数,允许使用getter和setter方法访问属性。企业JavaBean不是一个类,而是一个完整的组件模型(同样,EJB 3降低了企业JavaBean的复杂性)。

As designs using POJOs have become more commonly-used, systems have arisen that give POJOs some of the functionality used in frameworks and more choice about which areas of functionality are actually needed. Hibernate and Spring are examples.

随着使用pojo的设计越来越普遍,出现了一些系统,为pojo提供了框架中使用的一些功能,并提供了更多关于哪些功能领域实际上是需要的选择。Hibernate和Spring就是例子。

Value Object

A Value Object or VO is an object such as java.lang.Integer that hold values (hence value objects). For a more formal definition, I often refer to Martin Fowler's description of Value Object:

值对象或VO是一个对象,如java.lang。保存值(因此是值对象)的整数。对于更正式的定义,我经常参考Martin Fowler对价值对象的描述:

In Patterns of Enterprise Application Architecture I described Value Object as a small object such as a Money or date range object. Their key property is that they follow value semantics rather than reference semantics.

在企业应用程序体系结构的模式中,我将Value对象描述为一个小对象,例如Money或date range对象。它们的关键属性是遵循值语义而不是引用语义。

You can usually tell them because their notion of equality isn't based on identity, instead two value objects are equal if all their fields are equal. Although all fields are equal, you don't need to compare all fields if a subset is unique - for example currency codes for currency objects are enough to test equality.

你通常可以告诉他们,因为他们的平等概念不是基于身份,而是如果两个值对象的所有字段都是相等的。虽然所有字段都是相等的,但是如果一个子集是唯一的,则不需要对所有字段进行比较——例如,货币对象的货币代码足以测试等式。

A general heuristic is that value objects should be entirely immutable. If you want to change a value object you should replace the object with a new one and not be allowed to update the values of the value object itself - updatable value objects lead to aliasing problems.

一般的启发式是,值对象应该是完全不可变的。如果您想要更改一个值对象,您应该用一个新的对象替换该对象,并且不允许更新值对象本身的值——可更新的值对象会导致别名问题。

Early J2EE literature used the term value object to describe a different notion, what I call a Data Transfer Object. They have since changed their usage and use the term Transfer Object instead.

早期的J2EE文献使用“值对象”一词来描述不同的概念,我称之为数据传输对象。此后,他们改变了用法,转而使用术语“传输对象”。

You can find some more good material on value objects on the wiki and by Dirk Riehle.

你可以在wiki和Dirk Riehle身上找到一些更优秀的东西。

Data Transfer Object

Data Transfer Object or DTO is a (anti) pattern introduced with EJB. Instead of performing many remote calls on EJBs, the idea was to encapsulate data in a value object that could be transfered over the network: a Data Transfer Object. Wikipedia has a decent definition of Data Transfer Object:

数据传输对象或DTO是EJB引入的(反)模式。与其在ejb上执行许多远程调用,不如将数据封装在一个值对象中,这个值对象可以通过网络传输:一个数据传输对象。Wikipedia对数据传输对象有一个很好的定义:

Data transfer object (DTO), formerly known as value objects or VO, is a design pattern used to transfer data between software application subsystems. DTOs are often used in conjunction with data access objects to retrieve data from a database.

数据传输对象(DTO),以前称为值对象或VO,是一种用于在软件应用子系统之间传输数据的设计模式。dto通常与数据访问对象一起使用,以从数据库中检索数据。

The difference between data transfer objects and business objects or data access objects is that a DTO does not have any behaviour except for storage and retrieval of its own data (accessors and mutators).

数据传输对象和业务对象或数据访问对象之间的区别是,DTO除了存储和检索自己的数据(访问器和mutators)之外没有任何行为。

In a traditional EJB architecture, DTOs serve dual purposes: first, they work around the problem that entity beans are not serializable; second, they implicitly define an assembly phase where all data to be used by the view is fetched and marshalled into the DTOs before returning control to the presentation tier.

在传统的EJB体系结构中,dto有两个用途:首先,它们解决实体bean不可序列化的问题;其次,它们隐式地定义了组装阶段,在将控制权返回到表示层之前,视图使用的所有数据都将被获取并编组到dto中。


So, for many people, DTOs and VOs are the same thing (but Fowler uses VOs to mean something else as we saw). Most of time, they follow the JavaBeans conventions and are thus JavaBeans too. And all are POJOs.

因此,对于许多人来说,dto和VOs是相同的东西(但是Fowler使用VOs来表示我们看到的其他东西)。大多数时候,它们遵循JavaBeans的约定,因此也是javabean。和所有pojo。

#2


45  

DTO vs VO

DTO和签证官

DTO - Data transfer objects are just data containers which are used to transport data between layers and tiers.

数据传输对象只是数据容器,用于在层和层之间传输数据。

  • It mainly contains attributes. You can even use public attributes without getters and setters.
  • 它主要包含属性。您甚至可以使用没有getter和setter的公共属性。
  • Data transfer objects do not contain any business logic.
  • 数据传输对象不包含任何业务逻辑。

Analogy:
Simple Registration form with attributes username, password and email id.

类比:简单的注册表单与属性用户名、密码和电子邮件id。

  • When this form is submitted in RegistrationServlet file you will get all the attributes from view layer to business layer where you pass the attributes to java beans and then to the DAO or the persistence layer.
  • 当这个表单在RegistrationServlet文件中提交时,您将从视图层获得所有属性,然后将属性传递给java bean,然后传递给DAO或持久性层。
  • DTO's helps in transporting the attributes from view layer to business layer and finally to the persistence layer.
  • DTO帮助将属性从视图层传输到业务层,最后传输到持久性层。

DTO was mainly used to get data transported across the network efficiently, it may be even from JVM to another JVM.

DTO主要用于通过网络有效地传输数据,它甚至可以从JVM到另一个JVM。

DTOs are often java.io.Serializable - in order to transfer data across JVM.

dto往往io。可串行化——以便跨JVM传输数据。

VO - A Value Object [1][2] represents itself a fix set of data and is similar to a Java enum. A Value Object's identity is based on their state rather than on their object identity and is immutable. A real world example would be Color.RED, Color.BLUE, SEX.FEMALE etc.

VO -值对象[1][2]表示自己是一组数据,类似于Java enum。值对象的标识基于它们的状态,而不是基于它们的对象标识,并且是不可变的。一个现实世界的例子就是颜色。红色,颜色。蓝色,性。女等。

POJO vs JavaBeans

POJO vs javabean

[1] The Java-Beanness of a POJO is that it's private attributes are all accessed via public getters and setters that conform to the JavaBeans conventions. e.g.

POJO的Java-Beanness是:它的私有属性都是通过符合javabean约定的公共getter和setter进行访问的。如。

    private String foo;
    public String getFoo(){...}
    public void setFoo(String foo){...}; 

[2] JavaBeans must implement Serializable and have a no-argument constructor, where as in POJO does not have these restrictions.

[2]JavaBeans必须实现Serializable并拥有一个无参数的构造函数,在POJO中没有这些限制。

#3


33  

Basically,

基本上,

DTO: "Data transfer objects " can travel between seperate layers in software architecture.

DTO:“数据传输对象”可以在软件架构的不同层之间传输。

VO: "Value objects " hold a object such as Integer,Money etc.

画外音:“价值对象”持有一个对象,如整数、货币等。

POJO: Plain Old Java Object which is not a special object.

普通的*ava对象,它不是一个特殊的对象。

Java Beans: requires a Java Class to be serializable, have a no-arg constructor and a getter and setter for each field

Java bean:要求一个Java类是可序列化的,有一个无arg构造函数,每个字段都有一个getter和setter。

#4


21  

Java Beans are not the same thing as EJBs.

Java bean不同于ejb。

The JavaBeans specification in Java 1.0 was Sun's attempt to allow Java objects to be manipulated in an IDE that looked like VB. There were rules laid down for objects that qualified as "Java Beans":

Java 1.0中的javabean规范是Sun尝试在一个类似VB的IDE中操作Java对象。对于符合“Java bean”条件的对象,有一些规则:

  1. Default constructor
  2. 默认构造函数
  3. Getters and setters for private data members that followed the proper naming convention
  4. 为遵循适当命名约定的私有数据成员获取和设置
  5. Serializable
  6. 可序列化的
  7. Maybe others that I'm forgetting.
  8. 也许是我忘记的其他人。

EJBs came later. They combine distributed components and a transactional model, running in a container that manages threads, pooling, life cycle, and provides services. They are a far cry from Java Beans.

后来的ejb。它们结合分布式组件和事务模型,运行在管理线程、池、生命周期和提供服务的容器中。它们与Java bean相去甚远。

DTOs came about in the Java context because people found out that the EJB 1.0 spec was too "chatty" with the database. Rather than make a roundtrip for every data element, people would package them into Java Beans in bulk and ship them around.

dto是在Java环境中出现的,因为人们发现EJB 1.0规范对数据库来说太“chatty”了。人们不会对每个数据元素进行往返,而是将它们批量打包到Java bean中,然后将它们发送出去。

POJOs were a reaction against EJBs.

pojo是对ejb的一种反应。

#5


2  

POJO : It is a java file(class) which doesn't extend or implement any other java file(class).

POJO:它是一个java文件(类),它不会扩展或实现任何其他java文件(类)。

Bean: It is a java file(class) in which all variables are private, methods are public and appropriate getters and setters are used for accessing variables.

Bean:它是一个java文件(类),其中所有的变量都是私有的,方法是公共的,并且适当的getter和setter用于访问变量。

Normal class: It is a java file(class) which may consist of public/private/default/protected variables and which may or may not extend or implement another java file(class).

正常类:它是一个java文件(类),它可能包含公共/私有/默认/受保护变量,这些变量可能或不会扩展或实现另一个java文件(类)。

#6


1  

First Talk About

第一次讨论

Normal Class - that's mean any class define that's a normally in java it's means you create different type of method properties etc.
Bean - Bean is nothing it's only a object of that particular class using this bean you can access your java class same as object..

普通类——这意味着任何类定义在java中都是正常的这意味着你创建了不同类型的方法属性等等。Bean - Bean什么都不是,它只是一个特定类的对象,使用这个Bean你可以访问你的java类和对象一样。

and after that talk about last one POJO

在那之后,最后一个波乔

POJO - POJO is that class which have no any services it's have only a default constructor and private property and those property for setting a value corresponding setter and getter methods. It's short form of Plain Java Object.

POJO - POJO是一个没有任何服务的类,它只有一个默认的构造函数和私有属性,这些属性用于设置值对应的setter和getter方法。它是普通Java对象的简短形式。

#1


684  

JavaBeans

A JavaBean is a class that follows the JavaBeans conventions as defined by Sun. Wikipedia has a pretty good summary of what JavaBeans are:

JavaBean是遵循Sun定义的JavaBean约定的类。*对javabean有一个很好的总结:

JavaBeans are reusable software components for Java that can be manipulated visually in a builder tool. Practically, they are classes written in the Java programming language conforming to a particular convention. They are used to encapsulate many objects into a single object (the bean), so that they can be passed around as a single bean object instead of as multiple individual objects. A JavaBean is a Java Object that is serializable, has a nullary constructor, and allows access to properties using getter and setter methods.

JavaBeans是可重用的Java软件组件,可以在构建器工具中可视化地操作。实际上,它们是符合特定约定的Java编程语言编写的类。它们用于将许多对象封装到一个对象(bean)中,以便它们可以作为一个bean对象传递,而不是作为多个单独的对象。JavaBean是可序列化的Java对象,具有一个nullary构造函数,允许使用getter和setter方法访问属性。

In order to function as a JavaBean class, an object class must obey certain conventions about method naming, construction, and behavior. These conventions make it possible to have tools that can use, reuse, replace, and connect JavaBeans.

为了作为JavaBean类函数,对象类必须遵守关于方法命名、构造和行为的某些约定。这些约定使能够使用、重用、替换和连接javabean的工具成为可能。

The required conventions are:

所需的约定:

  • The class must have a public default constructor. This allows easy instantiation within editing and activation frameworks.
  • 类必须具有公共默认构造函数。这允许在编辑和激活框架中进行简单的实例化。
  • The class properties must be accessible using get, set, and other methods (so-called accessor methods and mutator methods), following a standard naming convention. This allows easy automated inspection and updating of bean state within frameworks, many of which include custom editors for various types of properties.
  • 必须使用get、set和其他方法(所谓的accessor方法和mutator方法)访问类属性,遵循标准的命名约定。这允许在框架内自动检查和更新bean状态,其中许多框架包括用于各种类型属性的自定义编辑器。
  • The class should be serializable. This allows applications and frameworks to reliably save, store, and restore the bean's state in a fashion that is independent of the VM and platform.
  • 类应该是可序列化的。这使得应用程序和框架能够可靠地保存、存储和恢复bean的状态,这种方式与VM和平台无关。

Because these requirements are largely expressed as conventions rather than by implementing interfaces, some developers view JavaBeans as Plain Old Java Objects that follow specific naming conventions.

由于这些需求主要以约定的形式表示,而不是通过实现接口来表示,因此一些开发人员将JavaBeans视为遵循特定命名约定的普通旧Java对象。

POJO

A Plain Old Java Object or POJO is a term initially introduced to designate a simple lightweight Java object, not implementing any javax.ejb interface, as opposed to heavyweight EJB 2.x (especially Entity Beans, Stateless Session Beans are not that bad IMO). Today, the term is used for any simple object with no extra stuff. Again, Wikipedia does a good job at defining POJO:

一个普通的旧Java对象或POJO是一种最初引入的术语,用来指定一个简单的轻量级Java对象,而不是实现任何javax。ejb接口,与重量级ejb 2相反。x(特别是实体bean、无状态会话bean在我看来并没有那么糟糕)。今天,这个术语用于任何没有额外内容的简单对象。*在定义POJO方面做得很好:

POJO is an acronym for Plain Old Java Object. The name is used to emphasize that the object in question is an ordinary Java Object, not a special object, and in particular not an Enterprise JavaBean (especially before EJB 3). The term was coined by Martin Fowler, Rebecca Parsons and Josh MacKenzie in September 2000:

POJO是普通Java对象的缩写。这个名称用来强调所讨论的对象是一个普通的Java对象,而不是一个特殊的对象,尤其是一个企业JavaBean(特别是在EJB 3之前)。

"We wondered why people were so against using regular objects in their systems and concluded that it was because simple objects lacked a fancy name. So we gave them one, and it's caught on very nicely."

“我们想知道为什么人们如此反对在他们的系统中使用常规对象,并得出结论,这是因为简单对象缺少一个花哨的名称。”所以我们给了他们一个,而且很好地抓住了。”

The term continues the pattern of older terms for technologies that do not use fancy new features, such as POTS (Plain Old Telephone Service) in telephony, and PODS (Plain Old Data Structures) that are defined in C++ but use only C language features, and POD (Plain Old Documentation) in Perl.

该术语延续了不使用花哨新特性的技术的旧术语模式,如电话中使用POTS(普通的旧电话服务)和POD(普通的旧数据结构),它们在c++中定义,但只使用C语言特性,在Perl中使用POD(普通的旧文档)。

The term has most likely gained widespread acceptance because of the need for a common and easily understood term that contrasts with complicated object frameworks. A JavaBean is a POJO that is serializable, has a no-argument constructor, and allows access to properties using getter and setter methods. An Enterprise JavaBean is not a single class but an entire component model (again, EJB 3 reduces the complexity of Enterprise JavaBeans).

与复杂的对象框架相比,这个术语很可能得到了广泛的接受,因为它需要一个通用且容易理解的术语。JavaBean是可序列化的POJO,具有无参数构造函数,允许使用getter和setter方法访问属性。企业JavaBean不是一个类,而是一个完整的组件模型(同样,EJB 3降低了企业JavaBean的复杂性)。

As designs using POJOs have become more commonly-used, systems have arisen that give POJOs some of the functionality used in frameworks and more choice about which areas of functionality are actually needed. Hibernate and Spring are examples.

随着使用pojo的设计越来越普遍,出现了一些系统,为pojo提供了框架中使用的一些功能,并提供了更多关于哪些功能领域实际上是需要的选择。Hibernate和Spring就是例子。

Value Object

A Value Object or VO is an object such as java.lang.Integer that hold values (hence value objects). For a more formal definition, I often refer to Martin Fowler's description of Value Object:

值对象或VO是一个对象,如java.lang。保存值(因此是值对象)的整数。对于更正式的定义,我经常参考Martin Fowler对价值对象的描述:

In Patterns of Enterprise Application Architecture I described Value Object as a small object such as a Money or date range object. Their key property is that they follow value semantics rather than reference semantics.

在企业应用程序体系结构的模式中,我将Value对象描述为一个小对象,例如Money或date range对象。它们的关键属性是遵循值语义而不是引用语义。

You can usually tell them because their notion of equality isn't based on identity, instead two value objects are equal if all their fields are equal. Although all fields are equal, you don't need to compare all fields if a subset is unique - for example currency codes for currency objects are enough to test equality.

你通常可以告诉他们,因为他们的平等概念不是基于身份,而是如果两个值对象的所有字段都是相等的。虽然所有字段都是相等的,但是如果一个子集是唯一的,则不需要对所有字段进行比较——例如,货币对象的货币代码足以测试等式。

A general heuristic is that value objects should be entirely immutable. If you want to change a value object you should replace the object with a new one and not be allowed to update the values of the value object itself - updatable value objects lead to aliasing problems.

一般的启发式是,值对象应该是完全不可变的。如果您想要更改一个值对象,您应该用一个新的对象替换该对象,并且不允许更新值对象本身的值——可更新的值对象会导致别名问题。

Early J2EE literature used the term value object to describe a different notion, what I call a Data Transfer Object. They have since changed their usage and use the term Transfer Object instead.

早期的J2EE文献使用“值对象”一词来描述不同的概念,我称之为数据传输对象。此后,他们改变了用法,转而使用术语“传输对象”。

You can find some more good material on value objects on the wiki and by Dirk Riehle.

你可以在wiki和Dirk Riehle身上找到一些更优秀的东西。

Data Transfer Object

Data Transfer Object or DTO is a (anti) pattern introduced with EJB. Instead of performing many remote calls on EJBs, the idea was to encapsulate data in a value object that could be transfered over the network: a Data Transfer Object. Wikipedia has a decent definition of Data Transfer Object:

数据传输对象或DTO是EJB引入的(反)模式。与其在ejb上执行许多远程调用,不如将数据封装在一个值对象中,这个值对象可以通过网络传输:一个数据传输对象。Wikipedia对数据传输对象有一个很好的定义:

Data transfer object (DTO), formerly known as value objects or VO, is a design pattern used to transfer data between software application subsystems. DTOs are often used in conjunction with data access objects to retrieve data from a database.

数据传输对象(DTO),以前称为值对象或VO,是一种用于在软件应用子系统之间传输数据的设计模式。dto通常与数据访问对象一起使用,以从数据库中检索数据。

The difference between data transfer objects and business objects or data access objects is that a DTO does not have any behaviour except for storage and retrieval of its own data (accessors and mutators).

数据传输对象和业务对象或数据访问对象之间的区别是,DTO除了存储和检索自己的数据(访问器和mutators)之外没有任何行为。

In a traditional EJB architecture, DTOs serve dual purposes: first, they work around the problem that entity beans are not serializable; second, they implicitly define an assembly phase where all data to be used by the view is fetched and marshalled into the DTOs before returning control to the presentation tier.

在传统的EJB体系结构中,dto有两个用途:首先,它们解决实体bean不可序列化的问题;其次,它们隐式地定义了组装阶段,在将控制权返回到表示层之前,视图使用的所有数据都将被获取并编组到dto中。


So, for many people, DTOs and VOs are the same thing (but Fowler uses VOs to mean something else as we saw). Most of time, they follow the JavaBeans conventions and are thus JavaBeans too. And all are POJOs.

因此,对于许多人来说,dto和VOs是相同的东西(但是Fowler使用VOs来表示我们看到的其他东西)。大多数时候,它们遵循JavaBeans的约定,因此也是javabean。和所有pojo。

#2


45  

DTO vs VO

DTO和签证官

DTO - Data transfer objects are just data containers which are used to transport data between layers and tiers.

数据传输对象只是数据容器,用于在层和层之间传输数据。

  • It mainly contains attributes. You can even use public attributes without getters and setters.
  • 它主要包含属性。您甚至可以使用没有getter和setter的公共属性。
  • Data transfer objects do not contain any business logic.
  • 数据传输对象不包含任何业务逻辑。

Analogy:
Simple Registration form with attributes username, password and email id.

类比:简单的注册表单与属性用户名、密码和电子邮件id。

  • When this form is submitted in RegistrationServlet file you will get all the attributes from view layer to business layer where you pass the attributes to java beans and then to the DAO or the persistence layer.
  • 当这个表单在RegistrationServlet文件中提交时,您将从视图层获得所有属性,然后将属性传递给java bean,然后传递给DAO或持久性层。
  • DTO's helps in transporting the attributes from view layer to business layer and finally to the persistence layer.
  • DTO帮助将属性从视图层传输到业务层,最后传输到持久性层。

DTO was mainly used to get data transported across the network efficiently, it may be even from JVM to another JVM.

DTO主要用于通过网络有效地传输数据,它甚至可以从JVM到另一个JVM。

DTOs are often java.io.Serializable - in order to transfer data across JVM.

dto往往io。可串行化——以便跨JVM传输数据。

VO - A Value Object [1][2] represents itself a fix set of data and is similar to a Java enum. A Value Object's identity is based on their state rather than on their object identity and is immutable. A real world example would be Color.RED, Color.BLUE, SEX.FEMALE etc.

VO -值对象[1][2]表示自己是一组数据,类似于Java enum。值对象的标识基于它们的状态,而不是基于它们的对象标识,并且是不可变的。一个现实世界的例子就是颜色。红色,颜色。蓝色,性。女等。

POJO vs JavaBeans

POJO vs javabean

[1] The Java-Beanness of a POJO is that it's private attributes are all accessed via public getters and setters that conform to the JavaBeans conventions. e.g.

POJO的Java-Beanness是:它的私有属性都是通过符合javabean约定的公共getter和setter进行访问的。如。

    private String foo;
    public String getFoo(){...}
    public void setFoo(String foo){...}; 

[2] JavaBeans must implement Serializable and have a no-argument constructor, where as in POJO does not have these restrictions.

[2]JavaBeans必须实现Serializable并拥有一个无参数的构造函数,在POJO中没有这些限制。

#3


33  

Basically,

基本上,

DTO: "Data transfer objects " can travel between seperate layers in software architecture.

DTO:“数据传输对象”可以在软件架构的不同层之间传输。

VO: "Value objects " hold a object such as Integer,Money etc.

画外音:“价值对象”持有一个对象,如整数、货币等。

POJO: Plain Old Java Object which is not a special object.

普通的*ava对象,它不是一个特殊的对象。

Java Beans: requires a Java Class to be serializable, have a no-arg constructor and a getter and setter for each field

Java bean:要求一个Java类是可序列化的,有一个无arg构造函数,每个字段都有一个getter和setter。

#4


21  

Java Beans are not the same thing as EJBs.

Java bean不同于ejb。

The JavaBeans specification in Java 1.0 was Sun's attempt to allow Java objects to be manipulated in an IDE that looked like VB. There were rules laid down for objects that qualified as "Java Beans":

Java 1.0中的javabean规范是Sun尝试在一个类似VB的IDE中操作Java对象。对于符合“Java bean”条件的对象,有一些规则:

  1. Default constructor
  2. 默认构造函数
  3. Getters and setters for private data members that followed the proper naming convention
  4. 为遵循适当命名约定的私有数据成员获取和设置
  5. Serializable
  6. 可序列化的
  7. Maybe others that I'm forgetting.
  8. 也许是我忘记的其他人。

EJBs came later. They combine distributed components and a transactional model, running in a container that manages threads, pooling, life cycle, and provides services. They are a far cry from Java Beans.

后来的ejb。它们结合分布式组件和事务模型,运行在管理线程、池、生命周期和提供服务的容器中。它们与Java bean相去甚远。

DTOs came about in the Java context because people found out that the EJB 1.0 spec was too "chatty" with the database. Rather than make a roundtrip for every data element, people would package them into Java Beans in bulk and ship them around.

dto是在Java环境中出现的,因为人们发现EJB 1.0规范对数据库来说太“chatty”了。人们不会对每个数据元素进行往返,而是将它们批量打包到Java bean中,然后将它们发送出去。

POJOs were a reaction against EJBs.

pojo是对ejb的一种反应。

#5


2  

POJO : It is a java file(class) which doesn't extend or implement any other java file(class).

POJO:它是一个java文件(类),它不会扩展或实现任何其他java文件(类)。

Bean: It is a java file(class) in which all variables are private, methods are public and appropriate getters and setters are used for accessing variables.

Bean:它是一个java文件(类),其中所有的变量都是私有的,方法是公共的,并且适当的getter和setter用于访问变量。

Normal class: It is a java file(class) which may consist of public/private/default/protected variables and which may or may not extend or implement another java file(class).

正常类:它是一个java文件(类),它可能包含公共/私有/默认/受保护变量,这些变量可能或不会扩展或实现另一个java文件(类)。

#6


1  

First Talk About

第一次讨论

Normal Class - that's mean any class define that's a normally in java it's means you create different type of method properties etc.
Bean - Bean is nothing it's only a object of that particular class using this bean you can access your java class same as object..

普通类——这意味着任何类定义在java中都是正常的这意味着你创建了不同类型的方法属性等等。Bean - Bean什么都不是,它只是一个特定类的对象,使用这个Bean你可以访问你的java类和对象一样。

and after that talk about last one POJO

在那之后,最后一个波乔

POJO - POJO is that class which have no any services it's have only a default constructor and private property and those property for setting a value corresponding setter and getter methods. It's short form of Plain Java Object.

POJO - POJO是一个没有任何服务的类,它只有一个默认的构造函数和私有属性,这些属性用于设置值对应的setter和getter方法。它是普通Java对象的简短形式。