← All topics
Quiz: Observer, Strategy and Decorator: questions with answers
10 questions, each with the answer and a short explanation.
Take the timed quiz + get a certificate →- Q1. In the Observer pattern, what does the subject know about its observers?
- Q2. What does this print? (code)
- Q3. Collections.sort(list, comparator) is an example of which pattern?
- Q4. A canteen bill uses if (type == STUDENT) … else if (type == STAFF) …. Which pattern removes this chain?
- Q5. What does this print? (code)
- Q6. Why must a decorator implement the same interface as the object it wraps?
- Q7. With 3 optional coffee add-ons, how many subclasses would you need to cover every combination (including plain coffee) without Decorator?
- Q8. Which JDK class is a well-known Decorator?
- Q9. What is a common bug when using the Observer pattern in long-running apps?
- Q10. Decorator differs from inheritance because a decorator: