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.
- A. 3
- B. 4
- C. 2
- 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.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- A class Invoice has methods calculateTotal(), saveToDatabase() and renderPdf(). Which principle does it violate, and what is the usual fix?
- A Worker interface declares work(), eat() and sleep(). RobotWorker implements it and leaves eat() and sleep() throwing 'not supported'…
- How many of these subclass changes violate the Liskov Substitution Principle? 1. The overriding method accepts a wider range of inputs…
- An area calculator contains if shape.type == "circle": … elif shape.type == "square": …, and every new shape requires editing this…
- How many of these statements are correct? 1. Dependency Inversion is a design principle: high- and low-level modules should both depend on…
- Code contains order.getCustomer().getAddress().getCity().toUpperCase(). Which principle does it most directly violate, and why does it…