Are they synonyms, a subset of each other, or completely different?

Are the concepts mentioned in the title of the question synonymous to a certain extent? Where are the main differences (context, structure, ...) and can a subset of the other be considered? Here are some brief definitions taken from Wikipedia.

POJO (regular Java object) Wikipedia

In computing software, POJO is an acronym for a regular Java object. the name is used to emphasize that this object is a regular 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 is a reusable component software for Java that can be visually visualized in a builder tool. In practice, they are classes written in Java programming, a language corresponding to a certain convention. They are used to encapsulate many objects in a single object (bean) so that they can be transferred as a separate bean object and not as several separate objects. A JavaBean is a serializable Java object, has a null constructor, and allows access to properties using the getter and setter Methods.

Wikipedia Value Object

A Data Transfer Object (DTO), formerly known as Value Objects or VO, is a design pattern used to transfer data between a subsystem software application. DTOs are often used in conjunction with data access objects to retrieve data from a database.

Wikipedia Business Object

A business object is a type of understandable person who is an actor within the business layer in an n-layer object-oriented computer program.

Connected:

Difference between DTO, VO, POJO, JavaBeans? What is the difference between JavaBean and POJO? DDD: what is the difference between objects and value objects?

+4
source share
4 answers

Not all of these classifications are related. Here is my understanding:

  • POJO is what its name suggests - a plain old Java object. This is nothing special. And this is exactly what we want to convey when we say that the object is a POJO. Today, most applications use some types of basic frameworks, and within the framework of frameworks there come requirements for objects that will integrate with the framework - the object must implement an interface or extend the class. When we say that a POJO object, we mean to say that it is a regular object and does not depend on any structure.

  • JavaBean is a java class that follows certain conventions described in your question. Such objects are often defined by certain structures that use reflection to determine the properties (accessible through getters / setters) of the object and manipulate them, for example. beans, access to JSP, Spring beans, etc. The good thing about JavaBeans is that they are still POJOs. Although they conform to certain conventions, conventions are not defined by any particular structure, but rather are defined by the Sun Javabean standard, and classes are still simple Java classes that are not associated with any third-party classes or interfaces.

  • Business objects refer to objects that are objects of your business domain. They are usually located in your business layer β€” the layer where all business logic resides. These objects are usually mapped to entity storage entities, for example. tables. These objects can be POJOs, JavaBeans, EJBs, etc.

  • Value objects are a type of design pattern. In some small web applications, you can also use your business objects at the web level. However, in larger or J2EE applications, you define value objects to move information from the business layer to the web layer. That is why they are also called data transfer objects (DTOs). These objects usually have only attributes that are needed at the web level and leave the attributes of business objects intended for consumption by the business layer. They can also have β€œcomputed” attributes that are generated at the business level. Using these templates helps separate business and web layers.

+6
source

Here is my trick:

  • Business objects are a generic term for an abstract idea of ​​what represents your problem. You can implement them in any language. In Java, you have additional features for make, because they can be POJO or EJB, mutable or immutable.
  • Value or DTO objects are used to transfer data between layers. They are usually unchanged. They can be implemented as POJO or Java Beans. Think of them as another subset of POJO.
  • The Java Bean meets Sun's original specification. They were designed to provide an interface that would allow them to easily connect to the VB-style IDE. Think of it as a subset of POJO.
  • People sometimes get confused about the difference between Java Beans and Enterprise Java Beans. Java Beans are part of the original Java 1.0 specification, intended as VB components (remember the "Bean Box"?). Enterprise Java Beans was the next specification that describes how special Java objects implement specific interfaces for interacting with the Java EE application server. An application server is a transaction monitor for a distributed component architecture that will handle threads, persistence, pooling, the life cycle of objects, messaging, naming, etc. EJB is a very special subset of Java objects that work only in the context of a Java EE server application.
  • POJO can be implemented in accordance with the Java Bean standard, but this is not a requirement. Any Java object qualifies as a POJO. It was originally intended to distinguish them from EJB version 2.0, which required several interfaces to communicate properly with the Java EE application server.
+3
source

The question is whether it is a mistake to use some of them as synonyms (for example, I heard how some people do it), and if this classification can be considered as a subset or another.

It is a mistake to use these terms as synonyms. They clearly have certain meanings. These quotes (and those contained in other answers) make this clear.

However, if many (or even all) of these terms are often used to describe the same object or objects. All this is a matter of perspective; those. what aspect of the object (s) you are trying to emphasize.

+1
source

Synthesis (from answers received):

  • POJO : an ordinary object without dependence on any structure. It can be adapted to meet the Java Bean standard without the requirement as such.
  • JavaBean : An object that conforms to the Sun JavaBean or Java 1.0 specification (see the Bean section). They were originally designed to provide an interface, so they could easily be connected to a VB-style IDE. It can be considered as a subset of POJO and remain independent of the frameworks. It can use certain mechanisms, such as reflection, to access properties.
  • Enterprise Java Bean . They should not be confused with Java Beans. With the simplifications introduced in version 3.0, EJBs can be considered equivalent POJOs. EJB itself is a specification that describes special Java objects that can interact with a Java EE server. The server itself acted as a transaction monitor in the context of a distributed component architecture that handles things like threads, persistence, federation, object lifecycle, messaging, and naming. Thus, EJB can be considered as a very special subset used in the context of the Java EE application server.
  • Business object . A theoretical concept or abstract idea that helps present a given problem. It represents business domain objects and is located at the business level of the application. They can be mapped to objects in the context of sustainability. An object can be POJO / JavaBean / EJB and be mutable or immutable.
  • Value / Data Transfer Object Uses a design template that helps unleash business and web layers. This matches the context of large applications where objects can pass between layers (for example, a business and a web layer). They are usually immutable in nature and can be configured as POJOs or Java Beans. One of the features is that they can contain computed attributes created at the business level.

PS: Reported as a wiki community, so feel free to edit.

0
source

Source: https://habr.com/ru/post/1315282/


All Articles