它们是同义词、互为子集还是完全不同?
问题标题中提到的概念在某种程度上是同义的吗?主要差异在哪里(背景、结构……)?一个可以被视为另一个的子集吗?以下是来自维基百科的一些简短定义。
POJO(普通旧 Java 对象) 维基百科
在计算软件中,POJO 是一个 普通旧 Java 对象的缩写。这 名称用于强调给定的 object 是一个普通的 Java 对象,而不是 一个特殊的物体,特别是 不是 Enterprise JavaBean。期限 由马丁·福勒、丽贝卡创造 帕森斯和乔什·麦肯齐 2000 年 9 月:
“我们想知道为什么人们如此反对在他们的 系统并得出结论认为 因为简单的物体缺乏花哨 姓名。所以我们给了他们一个,那就是 非常受欢迎。”
Java Bean 维基百科
JavaBeans是可重用的软件 Java 组件可以是 在构建器中进行可视化操作 工具。实际上,它们是类 用Java编程编写 符合特定语言 习俗。他们习惯了 将许多对象封装到一个对象中 对象(bean),这样它们就可以 作为单个 bean 对象传递 而不是作为多个个体 对象。 JavaBean 是一个 Java 对象 是可序列化的,有一个 nullary 构造函数,并允许访问 使用 getter 和 setter 的属性 方法。
值对象 维基百科
数据传输对象(DTO),以前 称为值对象或 VO,是 用于传输数据的设计模式 软件应用程序之间 子系统。 DTO 经常用于 与数据访问对象结合 从数据库检索数据。
业务对象 维基百科
业务对象是一种类型 可理解的实体是一个演员 在业务层内部 n层面向对象计算机 程序。
相关:
DTO、VO、POJO、JavaBean 之间的区别? JavaBean 和 POJO 之间有什么区别?< /a> DDD:差异有什么用实体和值对象之间?
Are the notions mentionned in the question title synonymous to a certain degree? Where do the main differences lie (context, structure, ...) and can one be considered a subset of another? Here's some brief definitions taken from Wikipedia.
POJO (Plain Old Java Object)
Wikipedia
In computing software, POJO is an
acronym for Plain Old Java Object. The
name is used to emphasize that a given
object is an ordinary Java Object, not
a special object, and in particular
not an Enterprise JavaBean. The term
was coined by Martin Fowler, Rebecca
Parsons and Josh MacKenzie in
September 2000:"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."
Java Bean Wikipedia
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.
Value Object 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.
Business Object Wikipedia
A business object is a type of an
intelligible entity being an actor
inside the business layer in a
n-layered object-oriented computer
program.
Related:
Difference between DTO, VO, POJO, JavaBeans?
What is the difference between a JavaBean and a POJO?
DDD: what's the use of the difference between entities and value objects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
并非所有这些分类都是相关的。我的理解是这样的:
POJO 顾名思义——一个普通的旧 Java 对象。没什么特别的。当我们说对象是 POJO 时,这正是我们想要传达的意思。如今,大多数应用程序都使用某种底层框架,并且框架对与框架集成的对象提出了要求 - 对象必须实现接口或扩展类。当我们说一个对象是 POJO 时,我们的意思是说它只是一个普通的对象,不依赖于任何框架。
JavaBean 是一个 java 类,遵循您的问题中所述的某些约定。此类对象通常由某些框架强制使用,这些框架使用反射来查找对象的属性(可通过 getter/setter 访问)并操作它们,例如暴露给 JSP、Spring beans 等的 bean。JavaBean 的好处在于它们仍然是 POJO 。尽管它们遵循某些约定,但这些约定不是由任何特定框架定义的,而是由 Sun Javabean 标准定义的,并且这些类仍然是普通 Java 类,与任何第三方框架的类或接口没有联系。
业务对象是指代表您的业务域实体的对象。这些通常驻留在您的业务层中 - 所有业务逻辑所在的层。这些对象通常映射到持久存储实体,例如表。这些对象可以是 POJO、JavaBean、EJB 等。
值对象是一种设计模式。在一些小型 Web 应用程序中,您也可以选择在 Web 层中使用业务对象。但是,在较大的应用程序或 J2EE 应用程序中,您可以定义值对象以将信息从业务层移动到 Web 层。这就是为什么它们也被称为数据传输对象 (DTO)。这些对象通常只具有 Web 层所需的属性,而保留了供业务层使用的业务对象的属性。它们还可能具有在业务层中生成的“计算”属性。使用此模式有助于解耦业务层和 Web 层。
Not all of these classifications are related. Here's my understanding:
POJO is what its name suggests - a plain old Java object. There's nothing special about it. And this is exactly what we want to convey when we say that an object is a POJO. Today most applications are using some kinds of underlying frameworks, and with the frameworks come requirements on the objects that will integrate with the framework - the object must implement an interface or extend a class. When we say an object is a POJO, we mean to say it is just an ordinary object and has no dependencies on any framework.
A JavaBean is a java class that follows certain conventions as described in your question. Such objects are often mandated by certain frameworks which use reflection to find out the properties (accessible through getters/setters) of the object and manipulate them e.g. beans exposed to JSPs, Spring beans etc. The good thing about JavaBeans is that they are still POJOs. Although they follow certain conventions, the conventions are not defined by any particular framework but are rather defined by Sun Javabean standard and the classes are still plain Java classes with no ties to any third party framework's classes or interfaces.
Business Objects refer to objects that represent your business domain entities. These usually reside in your business layer - the layer where all the business logic is. These objects usually map to persistence store entities e.g. tables. These objects could be POJOs, JavaBeans, EJBs etc.
Value objects are a type of design pattern. In some small web applications, you have the option of using your business objects in the web layer as well. However, in larger applications or J2EE applications, you define value objects to move information from the business layer to the web layer. That's why they are also called Data Transfer Objects (DTOs). These objects usually have only the attributes that are needed in the web layer and leave the attributes of business objects that were meant for business layer consumption behind. They may also have "computed" attributes that are generated in the business layer. Using this patterns helps decouple the business and web layers.
这是我的看法:
对于抽象的想法
代表你的问题。你可以
以任何语言实现它们。在
Java,你还有额外的选择
make,因为它们可以是 POJO 或
EJB,可变或不可变。
Here's my take:
for the abstract idea that
represents your problem. You can
implement them in any language. In
Java, you have additional choices to
make, because they can be POJOs or
EJBs, mutable or immutable.
将这些术语用作同义词是错误的。它们显然具有不同的含义。引用的定义(以及其他答案中提供的定义)清楚地表明了这一点。
然而,如果使用许多(甚至全部)这些术语来描述相同的一个或多个对象通常是有效的。这完全是一个视角问题;即您想要强调对象的哪个方面。
It is a mistake to use these terms as synonyms. They clearly have distinct meanings. The quoted definitions (and those provided in other answers) make this clear.
However, if it is often valid to use many (or even all) of these terms to describe the same object or objects. It is all a matter of perspective; i.e. what aspect of the object(s) you are trying to emphasize.
综合(根据给出的答案):
PS:标记为社区维基,因此可以随意编辑。
Synthesis (from answers given):
P.S: Marked as community wiki so feel free to edit.