Thursday, January 05, 2006

Proxy to create new classes implement a set of interfaces at runtime

As we do not know which interfaces to be implemented at compile time. Proxy can be used to implement a specific interfaces at run time.

(1) Bean box solution is poor in performance
(2) proxy is better solution to create new classes with specified interfaces
The generated proxy classes

1. implements all operations specified in the interfaces
2. all methods in Object class such as equals(), toString(), clone() etc

In summary, implement InvocationHandler, create new handler, create new Proxy
and do the work. There after, invocation handler will be invoked.

Object proxy = Proxy.newInstance(classLoader, interfaces, invocationHandler)

Here the specific interfaces can be sepcified for the create proxy class.
invocation hander can do
(1) route the call to remote servers
(2) associate the events with actions --- interfaces and invocationHandler
(3) do tracing on

Simple and Dynamic on fly

No comments: