POJO
One: What is Pojo
There are many names for Pojo, pure old Java object, plain ordinary Java object, and so on.
According to Martin Fowler's explanation is "Plain old Java object", literally translated as "pure older Java objects", but everyone uses "simple Java object" to call it.
The intrinsic meaning of Pojo refers to Java objects that do not inherit from any class, do not implement any interfaces, and are not invaded by other frameworks.
Two: Why do you have Pojo?
Java developers are mainly the complexity of the EJB to be afraid of, we have after reflection, and return to the "pure old-fashioned" javabean, that is, there is no parameter constructor, each field has getter and setter of the Java class.
Three: the meaning of Pojo
Pojo allows developers to focus on business logic and unit testing out of the framework. In addition, since Pojo does not need to inherit the framework's class or implement its interface, developers are extremely flexible in building inheritance structures and building applications.
The meaning of Pojo lies in its simplicity and flexibility, because it is simple and flexible, so that Pojo can be arbitrarily expanded, so as to be competent for many occasions, but also let a model through multiple layers become a reality.
First write a core Pojo, then implement the business logic interface and persistent interface, it becomes the domain Model, when the UI needs to be used, it implements the data binding interface and becomes VO (View Object).
Four: The difference between Pojo and Po, vo
Pojo refers to simple Java objects (Plain old Java Objects, pure old Java object, or Plain ordinary Java object).
Po refers to persistent objects (Persistant object persistent objects).
Vo refers to the value object or view object (Value object, view objects). Note that the VO in this article refers to view Object.
The persisted object must actually correspond to the entity in the database, so it differs from the Pojo. For example, Pojo is created by new and collected by GC. However, persistent objects are created by the Insert database and deleted by the database delete. Basically, the persistent object life cycle is closely related to the database. In addition, persistent objects often can only exist in a database connection, connnection closed, persistent objects will not exist, and Pojo as long as the GC is not recycled, always exists.
Because there are many differences, the persistent object Po (persistent object) is definitely different from Pojo in code, at least the PO will add some properties and methods to manage the database entity state relative to Pojo. The goal of ORM is to use the PO in the same way as Pojo, for programmers, they can use the PO as a pojo, and do not feel the existence of PO.
V: Expansion of the Pojo
Pojo contains only the simplest field properties, there is nothing superfluous, it is essentially an ordinary javabean.
But on the basis of Pojo, we can extend different objects.
Added a persistence method for Pojo (Insert, Update, Delete ...). After that, Pojo becomes a po.
With the addition of data binding capabilities for Pojo, Pojo becomes the view Object, the UI Model.
Methods for adding business logic to Pojo (such as document Review, transfer ...) After that, Pojo becomes the domain Model.
Pojo can also be used as a dto.
&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&& Javabean,pojo,po,vo,dto
JavaBean
In Java programs or JSP programs, there are a lot of code snippets can be reused, such as the operation of the database, the user's effectiveness check and some of the implementation of certain functions. In order to solve this problem well and improve the efficiency of development, Sun has introduced JavaBean, in short, JavaBean This is a Java class that implements a feature and is intended for re-use.
After using JavaBean in JSP, the separation between HTML and Java code can be realized, making JSP easier to develop and maintain. So JavaBean became one of the necessary tools for JSP programmers.
Although JavaBean is a Java class, it also has some of its own characteristics:
1, JavaBean is a public class
2. JavaBean has a method of constructing without parameters
3. The properties in JavaBean are operated by GETXXX () and setxxx ()
JavaBean is a reusable software component, as defined by Sun. In fact, JavaBean is a Java class that, by encapsulating properties and methods, becomes an object that has some kind of functionality or handles a business, referred to as a bean. Because
JavaBean is based on the Java language, so JavaBean does not rely on the platform, with the following features:
1. Can be used to implement code reuse
2. Easy to write, easy to maintain, easy to use
3. Can be used on any platform where the Java Runtime environment is installed, without recompiling.
For example, we write a Java class that calculates the area of the circle and calls it directly after Circlearea.java the area of the circle to be computed.
-----------------
From Baidu's explanation of Pojo:
The simple Java object (Plain ordinary Java Objects) is actually the ordinary JavaBean, the use of Pojo name is to avoid confusion with the EJB, and the abbreviation is more direct. Some of these properties and their getter setter methods can sometimes be used as value Object or a DTO (Data Transform object). Of course, if you have a simple arithmetic attribute is also possible, but not allowed to have a business method, There is no way to carry a connection or something.
Other explanations:
Pojo-plain old Java Objects, which is the "normal older Java object".
Matin Flower, one of the founders of the name, explains: "For people often forget about regular Java objects, my summary is that they don't have a good name-so in preparation for a speech, Rebecca Parsons, Josh Mackenzie and I gave the name: Pojo. "
Pojo is a transparent component that does not contain business logic, as it is named, and it is simple enough to be used only as a simple dto (data Transport object) or VO (Value object). It typically consists of a class that contains a private variable as a property and a getter and setter method that accesses its properties, and optionally adds a constructor to it. It is much like JavaBean for the first Pojo, but it should not include the processing of business logic in accordance with the design purpose that it should be easily combined with other components, which is also different from JavaBean.
Po-persistent object, which is persisted.
The PO is an entity in the Eims database, and the lifecycle is closely related to the database. The entity is created when a record is inserted into the database, and the entity dies when the database is deleted or closed. Many excellent open source frameworks have implemented the Pojo of the PO in the database using ORM, such as Hibernate,jdo.
Finally, let's summarize:
1.vo/dto is the value object and data Transform objects that are used as data
2.POJO, an abbreviation for plain Ordinary (old) Java object, is a javabean that does not contain business logic and is typically used as a vo/dto.
3.PO, the abbreviation for Persistence Object, comes from various JPA ORM (Java persistent API Object relational Mapping) providers such as Hibernate TopLink, Is the intermediate object that exists when interacting with the database, and can have various logical operations.
Pojo and Entity beans:
Pojo applies to the page data, is to save the data. (You might as well not do it, but this has become a norm.) )
An entity bean is associated with a database table and is an operation on a data table.
Other:
Pojo and JavaBean are our common two keywords, generally easy to confuse, Pojo full name is Plain ordinary Java object/plain old Java Object, Chinese can be translated into: Ordinary Java class, with a part getter/ The type of setter method can be called Pojo, but JavaBean is much more complex than Pojo, JavaBean is a component technology, as you do a wrench, and this wrench will be used in many places, this wrench also provides a variety of functions (you can take this wrench wrench, hammer, Pry and so on), and this wrench is a component.
First explain the above meaning:
The Pojo format is used for temporary transfer of data, which can only load data as a carrier of data storage, without the ability to handle business logic.
JavaBean Although the data acquisition and Pojo the same, but JavaBean can have other methods.
&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&& &&&&&&the difference between Pojo and JavaBean POJO (Plain old Java object) this name is used to emphasize that it is an ordinary Java object, not a special object. In the November 2005, "POJO" was used primarily to refer to Java objects that did not conform to a particular Java object model, conventions, or frameworks such as EJBS. Ideally, a POJO is a Java object that is not subject to any restrictions (except the Java language Specification). For example a pojo should not be
- Extend a predetermined class, such as public class Foo extends Javax.servlet.http.HttpServlet {...
- Implement a predetermined interface, such as public class Bar implements Javax.ejb.EntityBean {...
- Contains predefined annotations, such as @javax. Ejb.entity public class baz{...
Then, because of technical difficulties and other reasons, many compatible Pojo-style software products or frameworks actually still require the use of predetermined annotations, such as for more convenient persistence. JavaBean is a reusable component written in the Java language. Its method naming, construction and behavior must conform to a specific convention:
- This class must have a public default constructor.
- The properties of this class are accessed using getter and setter, and other methods conform to standard naming conventions.
- This class should be serializable.
Because these requirements are largely agreed upon rather than implemented by interfaces, many developers regard JavaBean as a pojo to comply with a particular naming convention. In short, when a pojo is serializable, there is a parameterless constructor, and when the getter and setter methods are used to access the property, he is a javabean.
Java Pojo (GO)