← Quiz: Observer, Strategy and Decorator: all 10 questions
Quiz: Observer, Strategy and Decorator · Question 6 of 10
Why must a decorator implement the same interface as the object it wraps?
Why must a decorator implement the same interface as the object it wraps?
- A.Java does not allow wrapping otherwise
- B.So the wrapped result can be used anywhere the original is used and wrapped again
- C.To make it faster
- D.So that it can be a Singleton
Answer & explanation
Correct answer: So the wrapped result can be used anywhere the original is used and wrapped again
Same interface means decorators can be stacked in any order.
Can you get the rest right without peeking?
Take the timed Quiz: Observer, Strategy and Decorator quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →