posted 20 years ago
Here is somewhat simplified example from the project I am currently working on:
Let's suppose we have an rmi handle on an object. As the communication channel is a little bit brittle, every method call on that object might fail. Based on the circumstances, we can retry the call, though. The retrying should be handled by a proxy.
There are several possibilities to code this proxy:
- Duplicate the error handling logic in every method. I hope we all agree that this is a bad idea.
- Extract the error handling into its own method and pass it a Strategy calling the correct method. That is actually how we did it until yesterday. Drawback is that you still have to touch the proxy every time the interface changes.
- Use a dynamic proxy. The InvocationHandler contains the error handling and uses reflection to call the method on the original object:
Did that help?
[ October 02, 2003: Message edited by: Ilja Preuss ]
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus