Skip to main content

Book Exercise Lanes

This module's exercise system is book-driven. Use these local chunks for targeted volume after you have already learned the pattern from the guide.

How To Use This Page

  1. Finish the relevant concept page first.
  2. Solve at least one kata of your own, from memory, before opening any chunk.
  3. Only then open the matching exercise lane.
  4. Keep a mistake log tagged with entries such as strategy for a one-off function, observer leak on disposal, command with hidden state, switch disguised as states, iterator that exposes internal cursor, handler that forgot to forward.

Lane 1: Variation -- Strategy and Template Method

Use this lane when the main pressure is "one algorithm, many variants" or "fixed skeleton, variable steps".

Target outcomes:

  • 1 refactor of a switch-heavy function to Strategy, tests green throughout
  • 1 Template Method refactor lifting shared steps with at least one hook
  • 2 comparisons where a function reference beat a Strategy object, documented

Lane 2: Notification -- Observer and Pub/Sub

Use this lane when the main pressure is "many readers, one writer" or cross-module event flow.

Target outcomes:

  • 1 defensive subject handling snapshot, re-entrancy policy, and exception isolation
  • 1 pub/sub bus with at least two topic schemas and three subscribers
  • 1 documented pitfall each: re-entrancy, subscriber leak, silent failure

Lane 3: Action Encapsulation -- Command, State, FSM

Use this lane when the main pressure is "actions must be recordable / reversible" or "lifecycle with many operations".

Target outcomes:

  • 1 Command-backed feature with undo, redo, and at least 5 command types
  • 1 State refactor from a switch-heavy class, with the switches removed
  • 1 FSM expressed as a transition table, every cell tested (ignored events included)

Lane 4: Traversal and Flow -- Iterator, Chain of Responsibility, Visitor

Use this lane when the pressure is "client should not know the layout" or "series of handlers / operations over a structure".

Target outcomes:

  • 1 tree iterator with two traversal orders, lazy
  • 1 CoR with 4+ handlers, order-documented, one test per stop condition
  • 1 Visitor with two visitors over the same element hierarchy, noting what growth pattern it favors

Self-Curated Problem Set

Build a custom set with these minimums:

  • 2 pattern-selection memos (given a scenario, choose and justify)
  • 4 "refactor from switch to pattern" exercises with tests
  • 2 "refactor out of pattern" exercises (remove a pattern that no longer earns its weight)
  • 1 end-to-end mini system combining at least three patterns (e.g., order lifecycle with Command + State + Observer)
  • 1 pitfall reproduction: cause, diagnose, fix, in that order

Completion Checklist

  • Completed at least two lanes in full
  • Logged at least 10 real mistakes with tags
  • Wrote at least 4 pattern-selection memos justifying the pattern chosen
  • Reattempted at least 3 failed refactors after review
  • One pattern demonstrated in a second language (usually Python ↔ TypeScript or Python ↔ Java)