[Design optimization]-correct use of the Value Object Mode, valueobject

Source: Internet
Author: User

[Design optimization]-correct use of the Value Object Mode, valueobject

In J2EE software development, system modules are usually layered, as shown in:



The presentation layer is mainly responsible for data presentation, the business road layer is responsible for specific business logic processing, and the persistence layer is responsible for database and other persistent operations.

In large systems, these layers are likely to be separated and deployed on different servers. The two layers may communicate by remotely calling RMI. For example, an order has three attributes: customer name, product name, and number. For example, three data interactions are required to obtain an order.

Although this mode is feasibleTwo serious problems:

First, from the perspective of object-oriented design, this method is unreasonable, cumbersome, and does not have good maintainability.

Second, an order is sent for three communications, and the performance is too low.

To solve this problem, you can useValue ObjectMode. In this mode, each attribute of an object is encapsulated to spread the encapsulated object in the network, so that the system can have a better interaction model and reduce network communication data, this improves system performance.

Optimized architecture model:


In this way, you only need to perform a remote call to obtain the complete Order information, which shortens the access response time and reduces network data traffic.

To implement such a model, we needPart 5.

The first role is the carrier of Order information: Order entity class

Public class Order implements Serializable {private static final long serialVersionUID =-limit 476071552949121l; private int orderId; private String clientName; private int number; private String productName; // The getter and setter methods are omitted}

The second role is the service interface called by the RMI server: IOrderManager Interface

public interface IOrderManager extends Remote {public Order getOder(int id) throws RemoteException;public String getClientName(int id) throws RemoteException;public int getProdName(int id) throws RemoteException;public int getNumber(int id) throws RemoteException;}

The third role is the implementation class of the server interface: OrderManager object

Public class OrderManager extends UnicastRemoteObject implements IOrderManager {private static final long serialVersionUID = bytes; // limits that only subclass or this package class can use protected OrderManager () throws RemoteException {super ();} @ Overridepublic Order getOder (int id) throws RemoteException {System. out. print ("Request received ed! ID = "+ id); Order o = new Order (); o. setClientName ("zq"); o. setNumber (1); o. setOrderId (2); o. setProductName ("Car"); return o;} @ Overridepublic String getClientName (int id) throws RemoteException {return "zq" ;}@ Overridepublic int getProdName (int id) throws RemoteException {return 0 ;}@ Overridepublic int getNumber (int id) throws RemoteException {return 1 ;}}

The fourth role is the RMI server: OrderManagerServer class

public class OrderManagerServer {public static void main(String[] args){try{LocateRegistry.createRegistry(1099);IOrderManager userManager = new OrderManager();Naming.bind("userManager", userManager);System.out.println("OrderManager is ready!");}catch (Exception e){System.out.println("OrderManager Server failed:"+e);}}}

The fifth is the client: OrderCient class

public class OrderManagerServer {public static void main(String[] args){try{LocateRegistry.createRegistry(1099);IOrderManager userManager = new OrderManager();Naming.bind("userManager", userManager);System.out.println("OrderManager is ready!");}catch (Exception e){System.out.println("OrderManager Server failed:"+e);}}}

We first open the server and then execute the client. The running results are as follows:

Server: OrderManager is ready!

Request received ed! ID = 1 Request received ed! ID = 1

Client: zq

Since then, a simple Value Object model has been implemented!


Obj = new Object ([value])

Obj can be used as the constructor Object () or Object (value );
That is to say, the Object construction method includes both parameters and parameters. Default constructor is used without parameters. If parameters are used, Object objects are initialized with parameters. In terms of code, this means that, but the Object does not have a constructor with parameters. I'm afraid your code is wrong.

How to optimize git to manage generated object files

Use the git gc command to compress historical information to save disk space.
You can use git help gc to check the description.
 

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.