Attach additional responsibilities to an object dynamically. Proxys provide a flexible alternative to subclassing for extending functionality.
PerfectJPattern's offers a componentized version of the Proxy pattern. In order to implement
proxies and take advantage of PerfectJPattern's implementation, users are required to extend
and optionally override the
invokeUnderlying method. The
will intercept all method calls on the real Subject instance.
See example below or checkout the
SynchronizedProxy.java implementation that will protect any Subject type from
race-conditions. This implementation would replace the need for e.g.
Collections.synchronizedList(...), etc. See example under
Implementing proxies using PerfectJPattern's
AbstractProxy offers the following
equalsis automatically handled to match that of the Subject, thus to the outside world the Proxy still is the Subject assuming