one, the Value object mode
In the Java EE Software Development, the system module is usually layered. The presentation Layer is mainly responsible for displaying the data, defining the UI organization pattern of the database, the business Logic Layer is responsible for the specific business logic processing, and the persistence layer usually refers to the database and related operations. In a large system, these layers are likely to be detached and deployed on different servers. Among the two levels, it is possible to communicate through the remote procedure call RMI, and so on.
As the following illustration shows, the presentation layer component takes the RMI client and obtains an order information through the middle business logic layer. Assuming that an order consists of a customer name, a product name, and a quantity, an interaction process may be described by the diagram, and the RMI client will interact with the server 3 times to obtain this information in turn.
Communication based on the above pattern is a feasible solution, but it has two serious problems:
(1) For the acquisition of an order object, this mode of operation is slightly cumbersome, and does not have a good maintainability .
(2) before and after the accumulation of 3 times the communication between the client and the server, high performance costs .
To solve these two problems, you can use the value object pattern. The Value object model advocates the encapsulation of the attributes of an object and the passing of the encapsulated objects in the network, so that the system has a better interaction model and reduces the network communication data, thus improving the system performance. Use the value object pattern to refine the above structure, define object order, maintain the customer name, commodity name, and quantity information by the order object, and the order object is the value object, which must be a serializable object. By applying the value object pattern to this example, you get the structure shown in Figure 2.16.
Figure 2.16 Value Object schema diagram
In the structure based on the value object pattern, only one network communication is needed to obtain an order information, which shortens the response time of data access and reduces the traffic of network data. Note: Using the value object pattern can effectively reduce the number of network interactions, improve the performance of remote invocation methods, and make the system interface more maintainable. Second, JavaBean
JavaBean is a Java class that follows a particular notation, which typically has the following characteristics:
This Java class must have a parameterless constructor attribute that must be privatized . The properties of privatization must be exposed to other programs through public-type methods, and the naming of methods must follow certain naming conventions.
JavaBean properties can be of any type, and a JavaBean can have multiple properties. Each attribute usually requires a corresponding setter, getter method, which is called the property modifier, and the Getter method is called a property accessor. The property modifier must start with a lowercase set prefix, followed by the property name, and the first letter of the property name is capitalized, for example, the modifier name of the Name property is the name of the modifier for the Setname,password property as SetPassword. The property accessor usually starts with a lowercase get prefix, followed by the property name, and the first letter of the property name is also capitalized, for example, the accessor name for the Name property is the Getname,password property's accessor name is GetPassword. A property of a javabean can also have only a set method or a Get method, which is often called a write-only, read-only property.
In use, Valueobject is generally defined as a JavaBean style for specification use.