Design Patterns: Naming a Solution That Keeps Recurring · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.

Names for solutions that keep recurring

Computing · Software Engineering · ages 19-21
Name ______________________   Date ____________
  1. A class must exist only once in the system. Which shape fits?

    • Strategy
    • Singleton
    • Observer
  2. What does a pattern name give a team?

    • A shared word for a recurring arrangement
    • A new programming language
    • A longer program
  3. A pattern is a magic ingredient you must always add wherever possible.

    Circle one:   True   False

  4. A status board must update whenever a sensor changes, without the sensor knowing the boards. Which shape?

    • Observer
    • Composition
    • Singleton
  5. Code swaps its fee rule at runtime by holding a swappable rule object, never naming a pattern. Which shape is it?

    • Singleton
    • Observer
    • Strategy
  6. An account class grows giant, doing sending and storing itself. How does composition help?

    • It adds more duties to the account
    • It moves sending and storing into small single job parts
    • It deletes the account class
  7. A part never varies and never swaps, yet a teammate wraps it in three swapping objects. What is wrong?

    • The wrapping adds indirection without buying anything
    • The code runs too fast
    • Nothing, more objects are always better
  8. A fixed value used in many places is typed out each time. What small pattern fixes it?

    • Copy it once more for safety
    • Hide it in a comment
    • Name the value once and refer to the name everywhere
LightMySky · lightmysky.comW1-mt_bhUEk8PwBp-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

Names for solutions that keep recurring W1-mt_bhUEk8PwBp-s1

  1. Singleton · Singleton exists to allow exactly one object of a class.
  2. A shared word for a recurring arrangement · One name lets everyone picture the same shape at once.
  3. False · Patterns are options; a plain function often does the job with less fuss.
  4. Observer · Producer tells listeners it never names: the observer shape.
  5. Strategy · Swapping behaviour at runtime by delegation is the strategy shape.
  6. It moves sending and storing into small single job parts · Small parts with one job each localize later changes.
  7. The wrapping adds indirection without buying anything · Patterns pay only when parts genuinely vary.
  8. Name the value once and refer to the name everywhere · Naming once means one change updates every use.
Worksheet · LightMySky