Creational Patterns  «Prev  Next»

Common Creational Patterns - Quiz

Each question is worth one point. Select the best answer or answers for each question.
1. Suppose you need to create new objects by copying an existing object. Which of the following patterns would you most likely use?
Please select the correct answer:
  A. Abstract Factory
  B. Builder
  C. Prototype
  D. Singleton

2. Suppose you need to define an interface for creating instances of several related abstract classes without specifying their concrete subclasses. Which of the following patterns would you most likely use?
Please select the correct answer:
  A. Abstract Factory
  B. Builder
  C. Prototype
  D. Factory Method

3. Suppose you need to define an abstract interface for creating a complex object from its component parts, but allow different subclasses to create different representations of the parts. Which of the following patterns would you most likely use?
Please select the correct answer:
  A. Abstract Factory
  B. Builder
  C. Prototype
  D. Factory Method

4. Which of the following is a real-world example of the Abstract Factory pattern in modern Java?
Please select the correct answer:
  A. java.sql.DriverManager.getConnection()
  B. java.sql.Connection (obtained via DriverManager)
  C. java.util.Arrays.sort()
  D. java.lang.String.valueOf()

5. Suppose you need to define an interface for creating a single object, but let subclasses decide which concrete class to instantiate. Which creational pattern would you most likely use?
Please select the correct answer:
  A. Abstract Factory
  B. Builder
  C. Prototype
  D. Factory Method

6. A development team is building a document editor that must produce different representations of the same document: one for print, one for the web, and one for mobile. Each representation requires the same construction steps but produces a different final result. Which creational pattern best fits this requirement?
Please select the correct answer:
  A. Singleton
  B. Prototype
  C. Builder
  D. Abstract Factory