Distinguish virtual, protection, and remote proxies in Java so the access concern is explicit instead of buried in a generic wrapper.
Java proxies usually fall into three practical categories.
flowchart TD
A["Proxy"] --> B["Virtual proxy"]
A --> C["Protection proxy"]
A --> D["Remote proxy"]
B --> E["Delay expensive creation or loading"]
C --> F["Authorize or deny access"]
D --> G["Represent a remote service locally"]
Use it when the real object is expensive and should only be created when needed.
Examples:
Use it when callers should see the same contract but not all have the same access rights.
Examples:
Use it when the real object lives on another machine or process and the local code should interact with a stand-in.
Examples:
Name the proxy by its access concern. If you cannot say what the proxy is controlling, it is probably just an undisciplined wrapper.