Bird
Raised Fist0

You want to add security checks and lazy initialization to a remote service without modifying its code. Which pattern should you use, and what is a key consideration?

hard🎤 Interviewer Follow-up Q10 of Q15
OOP & Design Patterns - Adapter vs Facade vs Proxy - Structural Pattern Comparison
You want to add security checks and lazy initialization to a remote service without modifying its code. Which pattern should you use, and what is a key consideration?
AUse Decorator to add security and lazy loading; ensure Decorator extends the service class
BUse Proxy to add security and lazy loading; ensure Proxy implements the same interface as the service
CUse Facade to add security and lazy loading; ensure Facade simplifies the interface
DUse Adapter to add security and lazy loading; ensure Adapter converts interfaces correctly
Step-by-Step Solution
Solution:
  1. Step 1: Identify pattern for access control and lazy initialization

    Proxy controls access and can implement lazy initialization transparently.
  2. Step 2: Key consideration for substitutability

    Proxy must implement the same interface as the service to be substitutable.
  3. Step 3: Why other options are incorrect

    Adapter converts interfaces but does not add access control; Facade simplifies interfaces but does not add security; Decorator adds responsibilities but is not intended for access control or lazy loading.
  4. Final Answer:

    Option B -> Option B
  5. Quick Check:

    Proxy adds control and lazy init, same interface required [OK]
Quick Trick: Proxy adds control, must match service interface [OK]
Common Mistakes:
MISTAKES
  • Confusing Adapter or Facade for access control
  • Assuming Decorator handles lazy loading
Trap Explanation:
PITFALL
  • Candidates often confuse Adapter or Facade with Proxy's access control role.
Interviewer Note:
CONTEXT
  • Tests deep understanding of Proxy's responsibilities and interface requirements.
Master "Adapter vs Facade vs Proxy - Structural Pattern Comparison" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes