18
The Proxy Pattern
The Proxy pattern is used when you need to represent an object that is complex or time consuming to create by a simpler one. If creating an object is expensive in time or computer resources, a proxy enables you to postpone this creation until you need the actual object. A proxy usually has the same methods as the object it represents; when the object is loaded, it passes on the method calls from the proxy to the actual object.
There are several cases where a Proxy can be useful:
If an object, such as a large image, takes a long time to load.
If the object is on a remote machine and loading it over the network might be slow, especially during peak network load periods.
If the object has limited access rights. The proxy then ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access