QA
Intermediate LevelSoftware Engineering Principles

What is the Proxy Pattern and how does it control access to underlying objects?

❓ Interview Prompt: Explain the Proxy Structural Pattern, Virtual Proxy (lazy loading), Protection Proxy (access control), and Caching Proxy implementations.

The Proxy Pattern provides a surrogate or placeholder object to control access to another underlying target object:

3 Types of Proxies:

1
Virtual Proxy: Delays expensive object initialization until actually accessed (Lazy Loading).
2
Protection Proxy: Checks authorization permissions before forwarding requests.
3
Caching Proxy: Intercepts requests to return cached results.

Code Implementation Example

typescript
interface Image { display(): void; }
class RealImage implements Image {
  constructor(private filename: string) { this.loadFromDisk(); }
  private loadFromDisk() { console.log('Loading heavy image...'); }
  display() { console.log('Displaying image'); }
}
// Virtual Proxy (Lazy Loading)
class ProxyImage implements Image {
  private realImage?: RealImage;
  constructor(private filename: string) {}
  display() {
    if (!this.realImage) this.realImage = new RealImage(this.filename);
    this.realImage.display();
  }
}
💡Lazy loading heavy resources using a Virtual Proxy.
🎯 Interview Key Takeaway

Use the Proxy pattern to control access, perform lazy initialization, or cache results for target objects.

#Proxy#Design Patterns#Structural#Intermediate
Back to all Software Engineering Principles Questions→

More Software Engineering Principles Interview Questions

Beginner LevelSoftware Engineering Principles

Explain the 5 SOLID Principles of Object-Oriented Software Design with practical refactoring examples.

Beginner LevelSoftware Engineering Principles

What are DRY (Don't Repeat Yourself), KISS (Keep It Simple, Stupid), and YAGNI (You Aren't Gonna Need It)?

Beginner LevelSoftware Engineering Principles

Why is Composition Over Inheritance a fundamental object-oriented design principle?