The Proxy Pattern is a structural design pattern that provides a surrogate or
placeholder for another object to control access to it. This pattern is useful
for adding functionality such as lazy initialization, access control, or logging
without altering the original object.
typeSubject={request():void;};classRealSubjectimplementsSubject{request():void{console.log("Real subject");}}classProxyimplementsSubject{privaterealSubject: RealSubject|undefined=undefined;// Lazy initialization
request():void{if(this.realSubject===undefined){// Check against null explicitly
this.realSubject=newRealSubject();}this.realSubject.request();}}constclient={run():void{constproxy: Subject=newProxy();// Type the proxy as Subject
proxy.request();constproxy2=newProxy();proxy2.request();// The RealSubject is only created once
}};client.run();