Why use Design Patterns? - Quiz Explanation

The correct answers are indicated below, along with text that explains the correct answers.
 
1. A design pattern is:
Please select the best answer.
  A. an algorithm used in object-oriented programming
  B. a data structure used in object-oriented programming
  C. a solution to a common problem in object-oriented programming
  D. a blueprint for a particular kind of class
  The correct answer is C. Design patterns are not algorithms nor are they data structures, though a typical design pattern may use both algorithms and data structures.
D is incorrect because a general design pattern describes the relationships between several classes or objects, rather just one. Furthermore, the design pattern probably only specifies parts of each class and object in its purview rather than the entire class.

2. Which of the following programming languages is best suited to design patterns?
Please select the best answer.
  A. Java
  B. C
  C. Cobol
  D. HTML
  The correct answer is A.
Java is best suited to design patterns. Design patterns describe object-oriented structures. C and Cobol are not object-oriented programming languages. HTML is not a programming language and is a mark-up language.

3. Which of the following techniques is a direct benefit of design patterns?
Please select the best answer.
  A. Faster analysis
  B. Faster coding
  C. Ease of testing solutions
  D. Modifying the program is easier
  The correct answer is B.
Design patterns let you write better code more quickly and have much less impact on the analysis, testing, or documentation phases.


4. Which of the following matters least in the use of a design pattern?
Please select the best answer.
  A. The pattern's name
  B. The problem the pattern solves
  C. The source code that implements the pattern
  D. The consequences of using the pattern
  The correct answer is C.
The source code that implements the pattern is not a fundamental part of the pattern anymore than the wood with which you build a house is a fundamental part of the blueprint for the house. A pattern can be implemented in any convenient object-oriented language. The details of the source are not important

5. Design pattern is to program as:
Please select the best answer.
  A. Metal is to car
  B. Park is to tree
  C. Blueprint is to building
  D. Mountain Dew is to soda
  The correct answer is C.
A blueprint describes the structure of the house but it is not the house or a part of the house. You can search through the house, and you likely won't find the blueprint anywhere. Nonetheless, it's presence is seen in the structure of the house, and the relationship between the different parts of the house to each other.


Classic Computer Science Problems