Java Dynamic Agent

Source: Internet
Author: User

First, what is a dynamic agent?

First we think about what is an agent? For example, in the real life of the boss on a business trip, you can not do something in the company, please his secretary "agent". In the program "agent" means that the original is a dry thing, but for some reason is not convenient to carry out, but through Class B to carry out their own duties, Class B is not a complete class A, it just called a Class A execution method, as the secretary agent is actually called the boss of a certain power.

Code implementation: in the proxy class's constructor to pass in the real object, then the real object can call its own method in the proxy class, thereby implementing the proxy, this is the idea of the agent. We look at the action from the outside like the proxy class implementation, in fact, the real object is implemented.

Agents are divided into static agents and dynamic agents. Static proxy is created by the programmer to create the source code to compile, before running it has fixed the type of real objects can be proxied, so when there are many different types of real objects to be proxied, the programmer will be different types of real objects to create different proxy classes, which is obviously very troublesome;

Dynamic agent is the reflection mechanism of Java, which dynamically obtains the type information when the program is running, and realizes the dynamic proxy.

Second, the implementation of dynamic agents:

  

  

Java Dynamic Agent

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.