7, Value object or Transfer object
The value object mode facilitates the exchange of data by reducing the message of distributed communication, typically where the communication is between the Web layer and the EJB layer. In a remote invocation, a single value object can be used to fetch a series of related data and provide it to the customer.
The appearance of this design pattern is based on the fact that the customer needs to exchange data with the EJB massively. Specifically, in the Java EE platform, application systems typically implement server-side program components as session beans and entity beans, and some of these components need to return data to the customer; In this case, a user often calls the relevant method multiple times until it gets the relevant information, and it should be noted that In most cases, the purpose of these method calls is to obtain a single message, such as a user name or a user address.
Obviously, on the Java EE platform, this kind of call is basically from the remote. That is, a user calling the appropriate method multiple times can put a huge burden on the web, even if the user and the EJB container load the same JVM, OS, and computer to run the EJB program, because the method call is assumed to be a remote task by default, the problem persists.
Because of the problems mentioned above, when the number of calls to the remote method increases, the related application performance will drop significantly, so it is inefficient to get a single message using multiple method calls; In this case, the Java EE researchers recommend using a Transfer object to contain all of the program data, That is, each method call can send and receive this transport object, and when a user makes a request to the EJB for the program data, the EJB creates the transport object, assigns its fields to the relevant values, and transmits the entire object to the user.
When the EJB uses the Transfer object, instead of using multiple method calls to get the value of each field in an object, the user can take a single method call to obtain the entire object, so that all calls or values for the transport object are local calls, because the transfer object is delivered to the user by value. Rather than a remote method call. It is important to note, however, that this transport object must have an access method corresponding to each property, or that all properties are public.
Class Figure 13 represents the architecture of the transport object pattern.
Figure 13 Transfer object class diagram