-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
TypeScript 5 Design Patterns and Best Practices - Second Edition
By :
The Proxy pattern is a structural design pattern that gives us a way to call methods on an object via another object (sometimes called a surrogate object). This pattern is particularly useful for adding a layer of control over how and when an object is accessed.
The Proxy pattern can also be used to control access to objects in terms of security and performance optimizations. For instance, a proxy can be used to lazy load a resource-intensive object or restrict access to sensitive data.
One analogy of this pattern is a company secretary accepting calls on behalf of the company director. They can regulate the flow of calls and may or may not forward them to the director based on who’s calling and why. This pattern works very similarly to the Decorator pattern that you learned about earlier. It also wraps an object and provides it with extra functionality.
With the Decorator pattern, you can wrap an object with the same interface and it will decorate...