The Jakarta Commons Sandbox ——Proxy
Commons Proxy: Dynamic Proxies Made Easy
The Proxy design pattern (GoF) allows you to provide "a surrogate or placeholder for another object to control access to it". Proxies can be used in many ways. Some of which are:
- Deferred Initialization - the proxy acts as a "stand-in" for the actual implementation allowing it to be instantiated only when absolutely necessary.
- Security - the proxy object can verify that the user actually has the permission to execute the method (a la EJB).
- Logging - the proxy can log evey method invocation, providing valuable debugging information.
- Performance Monitoring - the proxy can log each method invocation to a performance monitor allowing system administrators to see what parts of the system are potentially bogged down.
Commons Proxy supports dynamic proxy generation using proxy factories, object providers, invokers, and interceptors.
使用动态代理可以延迟初始化对象,使程序更安全,记录对象行为,性能监控