CS FundamentalsHardProduct-company design interview

How many of these differences between Proxy and Decorator are correct? 1. Both implement the same interface as the object they wrap. 2. A Proxy typically controls access (lazy loading, access checks, remote calls) while a Decorator adds behaviour. 3. A Proxy often creates or manages the lifetime of its real subject; decorators are usually stacked by the client. 4. A Decorator must always be a subclass of the class it decorates.

  1. A. 3
  2. B. 4
  3. C. 2
  4. D. 1

Correct answer: A. 3

Statements 1-3 are correct. 4 is false: a decorator implements the same interface and wraps an instance by composition; subclassing the concrete class is exactly what the pattern avoids.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic