Learn about Vo Pojo JavaBean dto

Source: Internet
Author: User
Tags access properties

1 What is VO,

(1.VO is created with the new keyword, collected by GC

The PO is created when new data is added to the database, and when data in the database is deleted. And can only survive in a database connection, the disconnection is destroyed

(2.VO is a value object, a business object that survives at the business level, is used by business logic, and the purpose of survival is to provide a place for the data to survive.) the PO is stateful, and each property represents its current state. It is the object representation of the physical data. Using it, we can decouple our programs from physical data and simplify the transformation between the object data and the physical data.

(The3.VO attribute is different depending on the current business, that is, each of its properties corresponds to the name of the data required for the current business logic.) the properties of the PO correspond to the field one by one of the database table.

2 What is Pojo

POJO (Plain ordinary Java object) simple java objects, actually is the ordinary JavaBeans, is to avoid and the abbreviation created by EJB obfuscation.

UsePOJOname is to avoid andEJB Mixed up, and the abbreviation is more direct. some of these properties and theirGetter Setterclass of the method,There is no business logic and can sometimes be used asVO (Value-object)ordto (Data Transform Object)to use.of course,It 's also possible if you have a simple arithmetic property.,but business methods are not allowed,also cannot carry aConnectionand other methods.

Features of 2.1Pojo

Pojo is plain  Ordinaryjava object entity beans java pojo

POJO can be understood as a simple entity class, as the name implies POJO class is convenient for programmers to use data tables in the database, for the vast number of programmers, can be very convenient to POJO Class is used as an object, but it is also convenient to call its get,set method. the POJO class also brings a lot of convenience to our configuration in the Struts framework.

2.2 Example

POJO has some private parameters as properties of the object. The get and set methods are then defined for each parameter as an interface for access. For example :

public class User {

Private long ID;

private String name;

public void SetId (long id) {

This. id = ID;

}

public void SetName (String name) {

This. Name=name;

}

Public long getId () {

return ID;

}

Public String GetName () {

return name;

}

}

POJO objects are sometimes referred to as Data objects, and are used in large numbers to represent objects in reality. If the Hibernate framework is used in the project, there is an associated XML file that corresponds to the table in the database, and the properties of the object correspond to the fields in the table.

3 What is JavaBean

JavaBean is a reusable component written in the JAVA language. To write JavaBean, the class must be concrete and public, and have a parameterless constructor. JavaBean exposes the member properties to the internal domain by providing a public method that conforms to the consistent design pattern. It is well known that property names conform to this pattern, and other Java classes can discover and manipulate the properties of these JavaBean through their own mechanisms

3.1 Requirements

JavaBean is a Java class that belongs to some specific decoding guidelines and extends the adaptability and scope to allow users to access internal properties and methods. With these,theJavaBean class can be used in the following ways:

(1. In the IDE ,JavaBean 's functionality allows the application developer to navigate through the methods in which the JavaBean is compiled, and cannot take advantage of the original source file.

(2. in the distributed style of Remote Method invocation (RMI) , this feature doesn't sound exciting, but in the future with Enterprise Edition JavaBean , that will change the situation.

(3. In order to JavaBean The property value and state can be saved to disk.

3.2 Range

the scope of JavaBean is a variable with a life time . JavaBean the range in

<jsp:usebean scope= "....> flag in the right side of the representation. will produce a Quick Reference for JavaBean.

Description: TheJSP server engine will peel <jsp.... Mark. and the actual code cannot be displayed on the end user's browser.

There are four types of scopes: page pages, request requests , Dialog sessions, application application .

3.3 Scope of the dialogue:

The JavaBean of the conversation scope is primarily applied across multiple pages and time periods: for example, populating user information. Add information and accept feedback to keep track of the user's recent page execution. The conversation scope JavaBean retains some information related to the user's conversation ID. This information is from a temporary conversation cookieand is removed from the client and server when theuser closes the browser.

3.3.1 Page/Request scope:

Page and request scope JavaBean are sometimes similar to forms of beans , because most of them are used to process forms. The form takes a long time to process the user's input, usually for the page to accept http/post or GET requests. Additional pages and request-scoped beans can be used to reduce the load on a large site server, and if you use a dialog Bean, the delayed processing can consume a lot of resources.

3.3.2 Applications:

The scope of application is typically applied to parts of the server, such as JDBC connection pooling, app monitoring, user count, and other classes that participate in user behavior.

restricting the generation of HTML in the Bean :

Theoretically,JavaBean will not produce any HTML, as this is The work of the JSP layer, however, for dynamic It is useful to provide some pre-prepared formats for the message. The resulting HTML will be returned by the callout's JavaBean method.

Here are some very important things:

(1. do not attempt to place any font dimensions in the HTML returned by JavaBean .

Not all browsers are the same. Many browsers cannot handle the full font size.

(2. do not attempt to place any script or DHTMLin the HTML returned by JavaBean .

outputting the script directly to the page or DHTML is equivalent to self-destruct, because some browser versions crash when processing an incorrect script (very few, but there are). If the user's JavaBean is dynamically rolled out in a complex HTML language at run time , the user will fall into a debugging nightmare. In addition, complex HTML will limit the lifetime and flexibility of JavaBean.

(3. do not provide any options.)

If a user uses a different system browse page, you can provide a way to replace it.

JavaBean is a reusable software component , as definedby 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, javabean does not rely on the platform, Has the following characteristics:

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

Writing JavaBean is writing a java class, so you can write a beanJust by writing a class,and an object created by this class is called a Bean . In order for the application building tools that use this bean , such as the JSP engine, to know the Properties and methods of the bean , you only need to adhere to the following rules on the method name of the class:

1. If the name of a member variable of a class is xxx, in order to change or get the value of a member variable, that is, to change or get a property, you can use two methods in the class:

GetXxx (), used to get property xxx.

Setxxx (), used to modify the attribute xxx. .

2. For Boolean -type member variables, which are properties of a Boolean logical type, allow "is " to replace the "get" above and the "Set" .

3. The access properties of a method in a class must be public .

4. If there is a constructor in the class, then the constructor is public and is parameterless.

4 What is a DTO

a DTO is an abbreviation for the dream take off English word, which means " dreaming off ". Just like the passionate young people of the music-loving DTO Team, we go forward with our dreams to the future and strive for music together. DTOs are also an abbreviation for a software application,Data Transfer Object.

4.1 Advantages and DisadvantagesAdvantages   Reduced number of remote calls. By transmitting more data in a single remote call, the application can reduce the number of remote calls. Improved performance. Remote calls can make your application run much less quickly. Reducing the number of calls is one of the best ways to improve performance. In most scenarios, a remote call that transmits large amounts of data takes almost the same amount of time as a call that transmits only a small number of data. Hide internal conditions. Passing more data back and forth in a single call can also more effectively hide the internals of a remote application behind a coarse-grained interface. This is the useRemote FacadeMode[FOWLER03]the main reason. Discover business Objects. In some cases, the definitionDTOhelps to find meaningful business objects. In the Create asDTOcustom classes, you will typically notice the grouping of elements displayed to the user or another system as a set of condensed information. Typically, these groupings serve as useful prototypes of objects that describe the business domain that the application handles. Testability. Encapsulating all parameters in a serializable object can improve testability. For example, you can fromXMLread in fileDTO, and call remote functions to test them. Again, you can easily serialize the results toXMLformat, and willXMLThe document is compared to the desired result without having to create a lengthy comparison script.
   DisadvantagesToo many classes may be required. If you chose to use a strongly typedDTO, you may have to create one for each remote method (or two if the return value is considered)DTO. Even in coarse-grained interfaces, this can result in a large number of classes. It can be difficult to write code of such a number of classes and to manage these classes. Using automatic code generation can alleviate this problem to some extent. Increase the amount of computation. Converting a data format on a server to a stream of bytes that can be transmitted across the network and converting back to the object format within a client application can have considerable overhead. Typically, data from multiple sources needs to be aggregated to a singleDTOthe. To improve the efficiency of remote calls over the network, additional calculations must be performed at either end to aggregate and serialize the information. Increase the coding effort. You can use a single line of code to complete the operation of passing parameters to the method. UseDTOrequires that the new object be instantiated and called for each parameterSettersand thegetters. Writing this code can be tedious.

Learn about Vo Pojo JavaBean dto

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.