Search code examples
javaproxy-classes

Could we say that Java Proxies work as delegators?


The aim behind asking this question is to improve my understanding of Java Proxies and delegation in general.


Solution

  • Semantically a Proxy delegates to some implementation, but that is just a side effect of the intention of the Proxy Pattern.

    The intention is to intercept and do extra logic or modify the logic before it does the delegation, or possibly affect the return value before the Proxy returns the results.

    The interception and modification isn't the intention of the Delegate Pattern.

    There it is an abstraction to make an interface in the system loosely coupled from the implementation.

    There is a concept of Dynamic Proxies in Java which are Java specific, and their intention is for building Adapter Pattern and Decorator Pattern implemenations.