iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

Quiz

Check your grasp of when each design pattern earns its keep.

Sample questions

EXAMPLE
# Design patterns quiz

1) You need one and only one database connection pool, lazily initialised, thread-safe.
   a) Singleton  b) Factory  c) Prototype  d) Builder

2) Construct complex objects step by step with optional fields, immutable result.
   a) Factory  b) Builder  c) Strategy  d) Adapter

3) Swap a sort algorithm at runtime without touching the caller.
   a) Strategy  b) Template Method  c) Decorator  d) State

4) Wrap an incompatible third-party API so your code can keep its own interface.
   a) Adapter  b) Facade  c) Proxy  d) Bridge

5) Add behaviour to an object dynamically without subclassing.
   a) Decorator  b) Composite  c) Visitor  d) Memento

6) One-to-many notification when state changes - and the publishers should not know subscribers.
   a) Observer  b) Mediator  c) Chain of Responsibility  d) Command

7) Encapsulate a request so it can be queued, logged, or undone.
   a) Command  b) State  c) Memento  d) Iterator

8) Walk a tree-shaped structure and perform different operations per node type.
   a) Visitor  b) Iterator  c) Composite  d) Template Method

Answers: 1a, 2b, 3a, 4a, 5a, 6a, 7a, 8a.

When you miss one, ask: what problem does that pattern actually solve? Patterns are vocabulary, not boilerplate.

Why it matters

Patterns are the names we give to recurring solutions - they are descriptive, not prescriptive. Reach for the name when explaining a design; do not build code around the name.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
// 3 questions per lesson.
Try it Yourself »

Discussion

Loading…