Bird
Raised Fist0

Which combination of structural patterns would best address these requirements?

hard🎤 Interviewer Follow-up Q15 of Q15
OOP & Design Patterns - Adapter vs Facade vs Proxy - Structural Pattern Comparison
Suppose you want to add logging and caching to a remote service without modifying its code. You also want to control access based on user roles. Which combination of structural patterns would best address these requirements?
AUse a Facade to control access and an Adapter to add logging and caching
BUse an Adapter to convert the service interface and a Facade to simplify access
CUse a Proxy to control access and a Decorator to add logging and caching
DUse a Proxy to add logging and caching and an Adapter to control access
Step-by-Step Solution
  1. Step 1: Analyze requirements

    Control access by user roles -> Proxy fits. Add logging and caching without modifying code -> Decorator fits.
  2. Step 2: Evaluate options

    A incorrectly assigns Facade for access control and Adapter for logging/caching. B misuses Adapter and Facade roles. C correctly assigns Proxy for access control and Decorator for adding behavior. D incorrectly uses Adapter for access control and Proxy for logging/caching.
  3. Final Answer:

    Option C -> Option C
Quick Trick: Proxy = access control; Decorator = add behavior; Adapter = interface conversion; Facade = simplify interface
Common Mistakes:
MISTAKES
  • Confusing Proxy and Decorator responsibilities
  • Using Adapter or Facade for access control
  • Assuming Proxy can add behavior like logging and caching
Trap Explanation:
PITFALL
  • Proxy controls access but does not add behavior; Decorator adds behavior; Adapter changes interfaces; Facade simplifies interfaces.
Interviewer Note:
CONTEXT
  • Tests deep understanding of pattern roles and combining them to solve complex design problems.
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