Well, a proxy object is an object that looks like (and can be used) like the "real" target object. Usually it delegates all invocations to the target object itself.
Due to its existence one is able to tweak the delegation process of one or all methods. So you are able to preprocess the invocation or postprocess its result or even abort it (by throwing an exception).
While Spring provides facilities to do all this stuff behind the scenes with declarative means it is easy to program a proxy object yourself. It's no magic in it.
Code:
public interface Foo {
void bar(String str);
}
public class FooImpl implements Foo {
public void bar(String str) {
System.out.println("bar: " + str);
}
}
public class FooProxy implements Foo {
private Foo delegate;
public void setDelegate(Foo delegate) {
this.delegate = delegate;
}
public void foo(String str) {
// here we can do something with str or throw an exception
this.delegate.foo(str);
// If we had a return value we could change it here
}
}
Hope that helps,
Andreas