Intercepting calls to objects

The more I research this the more I think that I'm making this up, but I seem to remember some way in Java to "intercept" calls to an object. For instance, if someone called setFoo(int) on an object, I could have some method that would catch every call to the object. This method would receive the name of the method being called, etc. (i.e., when "setFoo()" is called, this special method gets passed in a string called "setFoo". I could do some special processing, then dispatch the actual method call to "setFoo().")

I know you can do this sort of thing by creating an architecture that would support listeners on "foo", etc., but what I'm thinking of is more automatic, based on Java reflection functionality.

Does this exist in Java, or is this just a fantasy of mine?

Thanks.

[808 byte] By [gmaletica] at [2007-10-2 8:25:46]
# 1

You might be thinking of a proxy.

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Proxy.html

I doubt it's exactly what you're thinking of, but you might be able to use it to achieve the same or similar ends in some situations.

Or there might be something in Aspect Oriented Programming that would help you. Google for that, and/or for AspectJ.

jverda at 2007-7-16 22:25:42 > top of Java-index,Java Essentials,Java Programming...
# 2
Actually, I think this is what I'm thinking of, though it's not quite so flexible as I had implied in my description. Thanks very much!
gmaletica at 2007-7-16 22:25:42 > top of Java-index,Java Essentials,Java Programming...