它们是同义词、互为子集还是完全不同?

发布于 2024-09-09 10:14:47 字数 1901 浏览 4 评论 0原文

问题标题中提到的概念在某种程度上是同义的吗?主要差异在哪里(背景、结构……)?一个可以被视为另一个的子集吗?以下是来自维基百科的一些简短定义。

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 技术交流群。

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

发布评论

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

评论(4

梦开始←不甜 2024-09-16 10:14:47

并非所有这些分类都是相关的。我的理解是这样的:

  • 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.

清君侧 2024-09-16 10:14:47

这是我的看法:

  1. 业务对象是一个通用术语
    对于抽象的想法
    代表你的问题。你可以
    以任何语言实现它们。在
    Java,你还有额外的选择
    make,因为它们可以是 POJO 或
    EJB,可变或不可变。
  2. 值对象或 DTO 用于在层之间传送数据。它们通常是不可变的。它们可以实现为 POJO 或 Java Bean。将它们视为 POJO 的另一个子集。
  3. Java Bean 符合原始的 Sun 规范。它们旨在提供一个接口,使它们能够轻松插入 VB 风格的 IDE。将它们视为 POJO 的子集。
  4. 人们有时会对 Java Bean 和 Enterprise Java Bean 之间的区别感到困惑。 Java Bean 是原始 Java 1.0 规范的一部分,旨在类似于 VB 组件(还记得“Bean Box”吗?)。 Enterprise Java Bean 是随后的一个规范,描述了特殊的 Java 对象如何实现特定的接口以与 Java EE 应用服务器进行互操作。应用程序服务器是分布式组件架构的事务监视器,用于处理线程、持久性、池化、对象生命周期、消息传递、命名等。EJB 是 Java 对象的一个​​非常特殊的子集,仅在 Java EE 应用程序的上下文中工作服务器。
  5. POJO 可以实现为符合 Java Bean 标准,但这不是必需的。任何 Java 对象都有资格作为 POJO。它最初是为了将它们与 EJB 2.0 版区分开来,EJB 2.0 版需要多个接口才能与 Java EE 应用服务器正确互操作。

Here's my take:

  1. Business objects is a generic term
    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.
  2. Value objects or DTOs are used to ferry data between layers. They're usually immutable. They can be implemented as POJOs or Java Beans. Think of them as another subset of POJOs.
  3. A Java Bean conforms to the original Sun specification. They were intended to provide an interface that would allow them to be plugged into a VB-style IDE with ease. Think of these as a subset of POJO.
  4. People sometimes get confused about the difference between Java Beans and Enterprise Java Beans. Java Beans are part of the original Java 1.0 spec, intended to be like VB components (remember "Bean Box"?). Enterprise Java Beans were a spec that followed that described how special Java objects would implement specific interfaces to interoperate with a Java EE app server. The app server was a transaction monitor for a distributed component architecture that would handle threading, persistence, pooling, object lifecycle, messaging, naming, etc. EJBs are a very special subset of Java objects that work only within the context of a Java EE app server.
  5. A POJO can be implemented to conform to the Java Bean standard, but it's not a requirement. Any Java object qualifies as a POJO. It was originally meant to distinguish them from EJB version 2.0, which required several interfaces in order to interoperate with the Java EE app server properly.
天赋异禀 2024-09-16 10:14:47

问题是使用其中一些作为同义词是否是错误(就像我听说有些人这样做)以及给定的分类是否可以被视为子集或另一个。

将这些术语用作同义词是错误的。它们显然具有不同的含义。引用的定义(以及其他答案中提供的定义)清楚地表明了这一点。

然而,如果使用许多(甚至全部)这些术语来描述相同的一个或多个对象通常是有效的。这完全是一个视角问题;即您想要强调对象的哪个方面。

The questions is whether it's a mistake to use some of these as synonyms (like I've heard some people do) and if a given classification can be considered as a subset or another.

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.

心清如水 2024-09-16 10:14:47

综合(根据给出的答案):

  • POJO:一个不依赖于任何框架的普通对象。可以对其进行修改以符合 Java Bean 标准,但本身并不是这样的要求。
  • JavaBean:符合Sun JavaBean或Java 1.0规范的对象(参见“Bean框”)。它们最初的目的是提供一个接口,以便可以轻松地插入 VB 风格的 IDE。可以被视为 POJO 的子集并保持独立于框架。它可以采用某些机制(例如反射)来访问属性。
  • 企业 Java Bean:不应将它们与 Java Bean 混淆。通过 3.0 版本带来的简化,EJB 可以被视为等同于 POJO。 EJB 本身是一个描述可以与 Java EE 服务器互操作的特殊 Java 对象的规范。服务器本身在分布式组件架构的上下文中充当事务监视器,处理诸如线程、持久性、池化、对象生命周期、消息传递和命名等事务。因此,EJB 可以被视为 Java EE 应用服务器中使用的一个非常特殊的子集。
  • 业务对象:有助于表示给定问题的理论概念或抽象想法。它代表业务领域实体并驻留在应用程序的业务层中。它们可以映射到持久性上下文中的实体。该对象可以是 POJO/JavaBean/EJB,并且可以是可变的或不可变的。
  • 值对象/数据传输对象:采用有助于解耦业务层和 Web 层的设计模式。这是为了适应大型应用程序的环境,其中对象可以在层(例如业务层和 Web 层)之间传输。它们本质上通常是不可变的,并且可以格式化为 POJO 或 Java Bean。其特殊性之一是它们可以包含在业务层中生成的计算属性。

PS:标记为社区维基,因此可以随意编辑。

Synthesis (from answers given):

  • POJO: An ordinary object with no dependencies towards any framework. It can be adapted to conform to the Java Bean standard without being a requirement as such.
  • JavaBean: Object conforming to the Sun JavaBean or Java 1.0 specification (refer to "Bean box"). They were originally intended to provide an interface so they could be plugged into a VB-style IDE with little difficulty. Can be considered as a subset of POJOs and remain independant of frameworks. It can employ certain mecanisms such as reflection to access properties.
  • Enterprise Java Bean: These shouldn't be confused with Java Beans. With the simplifications brought about with version 3.0, EJBs can be considered as equivalent to a POJO. EJB in itself is a specification describing special Java Objects that can interoperate with a Java EE server. The server as such acted as a transaction monitor in the context of a distributed component architecture handling things such as threading, persistence, pooling, object lifecycle, messaging and naming. As such an EJB can be viewed as a very special subset that used in the contect of a Java EE application server.
  • Business object: Theoretical concept or abstract idea that helps to represent a given problem. It represents business domain entities and resides in the business layer of an application. They can be mapped to entities in the context of persistance. The object can be a POJO/JavaBean/EJB and be either mutable or immutable.
  • Value object/Data Transfer Object: Employs a design pattern which helps to decouple the business and web layers. This is to suit the context of large applications where objects can transit between layers (the business and web layer for example). They're usually immutable in nature and can either be formated as POJOs or Java Beans. One specificity is that they can contain computed attributes that are generated in the business layer.

P.S: Marked as community wiki so feel free to edit.

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