/**
 * Proxy is a structural design pattern that provides
 * a substitute or placeholder for another object. A
 * proxy controls access to the original object, allowing
 * you to perform something either before or after the
 * request gets through to the original object.
 */ interface Subject { request ( ) : string ; } export class RealSubject implements Subject { public request ( ) { return 'RealSubject' ; } } export class Proxy implements Subject { private realSubject : RealSubject ; private cache ? : string ; constructor ( realSubject ) { this . realSubject = realSubject ; } public request ( ) { if ( this . cache !== undefined ) { return `Cached: ${ this . cache }` ; } this . cache = this . realSubject . request ( ) ; return this . cache ; } }