Design Patterns - Static and dynamic proxy proxy mode

Original link: http://www.studyshare.cn/blog/details/1181/0

First, the concept

Proxy mode: providing a proxy class to control access to this object to other objects. In some cases, a subject is not suited or not directly applicable

Another object, the proxy object may function as an intermediary between the client and the target object 23 belonging to the proxy mode in structural design pattern design pattern.

Acting mode can be divided into static and dynamic proxy agent.

Agent structure as shown below:


 

For example: the customer (customer category) - "Shopping (proxy class) -" Overseas orders (orders from overseas class), ordinary customers can not directly go overseas orders, the purchasing company to

Orders, purchasing overseas companies to buy and offers to customers. At this point the company is the customer's purchasing agent.

java development tools Download and install tutorial Guinness, the point here .

More in-depth technical articles in here .

Second, the static agent

1, the concept of

The so-called static proxy proxy class that is generated source code by the programmer or tools, and then compile the proxy class, which is already present bytecode file proxy class before the program runs

Relations pieces, proxy class and delegate class before running is determined.

2, case studies

(1) Order Interface


 

(2) third-party order fulfillment class


 

(3) the proxy class


 

Third, the dynamic proxy

1, the concept of

Dynamic proxies are not concerned about the proxy class in the implementation phase, and which object was specified in the operational phase. When the need to achieve a certain class of non-invasive enhances its function,

The dynamic proxies, e.g. mybatis log printing function of sql

2, case studies

(1), a user interface


 

(2), the interface implementation class


 

(3), enhanced implementation class


 

(4) Test Class


 

(5), printout


 

 

Original articles, please indicate the source.

java development tools Download and install tutorial Guinness, the point here .

More in-depth technical articles in here .

Guess you like

Origin www.cnblogs.com/darendu/p/11653348.html