Card 09/ 09
Recap: Proxy Pattern
Same interface, one stand-in, and control over every call that comes from outside.
Proxy places a stand-in with the real object's interface in front of it, to control the calls that reach it.
- Intent. Provide a surrogate or placeholder for another object to control access to it.
- Participants. The subject interface, the real subject, the proxy that holds or creates it, and the client.
- Four kinds. Virtual creates on first use, protection checks permission, remote forwards over the network, caching returns a stored result.
- Against Decorator. The same shape; a proxy controls access to one subject and often creates it, while decorators add stackable features to an object they are handed.
- In the wild. JavaScript's
Proxywith its traps; Python's__getattr__, which does not forward special methods. - The trap. Self-calls inside the real object skip the proxy, which is why Spring's
@Transactionalfails on them.
← → move through sections and cards