Behavioral Patterns «Prev Next»

Common Behavioral Patterns - Quiz

Each question is worth one point. Select the best answer or answers for each question.
1. In Java 21+, which pattern is most directly supported by sealed classes and pattern matching in switch expressions as a modern alternative to classic double-dispatch?
Please select the correct answer:
  A. Chain of Responsibility
  B. Visitor
  C. Strategy
  D. Mediator

2. The GoF Observer pattern is foundational to modern reactive programming in Java. Which of the following represents the current Java standard API for reactive publish-subscribe streams, introduced in Java 9?
Please select the correct answer:
  A. java.util.Observable
  B. java.util.EventListener
  C. java.util.concurrent.Flow
  D. java.beans.PropertyChangeListener

3. Which of the following patterns allows multiple objects an opportunity to process a request without guaranteeing that any of them must process it?
Please select the correct answer:
  A. Chain of Responsibility
  B. Command
  C. Memento
  D. Mediator

4. Suppose you want to convert the interface of a class into a different interface that clients expect. Which of the following patterns allows you to do that?
Please select the correct answer:
  A. Adapter
  B. Bridge
  C. Composite
  D. Façade

5. Suppose you want to separate an abstraction from its implementation so that the two can vary independently. Which of the following patterns allows you to do that?
Please select the correct answer:
  A. Adapter
  B. Bridge
  C. Proxy
  D. Decorator

6. Suppose you want to compose objects into tree structures to represent part-whole hierarchies, and allow clients to treat individual objects and compositions of objects uniformly. Which of the following patterns allows you to do that?
Please select the correct answer:
  A. Façade
  B. Bridge
  C. Composite
  D. Flyweight