Spring Tech Insider Reading notes-what is Pojo mode

Source: Internet
Author: User

Today in the "Spring Technology Insider", the first chapter has repeatedly mentioned the use of Pojo to complete the development, Baidu a bit, in this reserve

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

The concept of Poco is borrowed from Java's Pojo, and the meaning of the two is consistent, and the difference is not just the language used. So Poco's explanation is "Plain old C # Object".

2. Why are there 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.

3. 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).

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

5. Extension 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.

Spring Tech Insider Reading notes-what is Pojo mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.