# Statuses and Routes

Sequence diagrams first, because from here on the problems are about who calls whom; then a package whose status decides what it can do, and a route walked one stop at a time.

Updated: November 17, 2026

## [Drawing Behavior](https://www.ask-codey.com/courses/design-patterns/topics/dp-drawing-behavior)

1. [Sequence Diagrams: Who Calls Whom, in Order](https://www.ask-codey.com/lessons/dp-sequence-diagrams) (Apprentice): From this pass on, the design problems are about calls: who asks whom, in what order, and what comes back; a sequence diagram draws exactly that, as lifelines read from top to bottom, starting with a package scanned at the depot.
2. [Sequence Diagrams: Loops, Choices and Waiting](https://www.ask-codey.com/lessons/dp-sequence-diagram-frames) (Journeyman): Real calls repeat, branch and sometimes don't wait for an answer; a sequence diagram shows each with a loop frame, an alt frame, an object created partway down, and an open arrowhead, and Mermaid writes the whole diagram as a few lines of text.

## [Plan It, Build It](https://www.ask-codey.com/courses/design-patterns/topics/dp-plan-it-build-it-statuses-and-routes)

1. [Meet the Package Tracker: Plan It, Build It](https://www.ask-codey.com/lessons/dp-tracker-version-1) (Apprentice): The second pass starts with Lakeside Parcel's package tracker: what it does, its class diagram and the sequence diagram of its main call, version 1 in five languages, and the list of what's likely to change, which turns into this pass's problems.

## [What It Can Do Depends on Where It Is](https://www.ask-codey.com/courses/design-patterns/topics/dp-what-it-can-do-depends-on-where-it-is)

1. [State: What You Can Do Depends on Where It Is](https://www.ask-codey.com/lessons/dp-state) (Journeyman): When every method of a package starts by checking its status, a new status means editing every method, and the one you miss breaks a rule; drawing the rules as a state diagram, then giving each status its own class, puts each status's rules in one place: the State pattern.

## [Walking the Route](https://www.ask-codey.com/courses/design-patterns/topics/dp-walking-the-route)

1. [Iterator: Next Stop, Please](https://www.ask-codey.com/lessons/dp-iterator) (Journeyman): When every piece of code that walks a route has its own loop over how the route is stored, changing the storage breaks all of them; an iterator hands out the stops one at a time, so callers ask for the next stop and never learn whether it came from a list, zones or a server.
2. [Generators: Iterators the Modern Way](https://www.ask-codey.com/lessons/dp-generators) (Journeyman): A hand-written iterator is a bookmark and a page of bookkeeping; a generator writes the same iterator as an ordinary loop that hands out each item with yield, pausing until the next one is asked for, so stops can even be fetched from a server only when they're needed.

## [Exercise: The Package Tracker](https://www.ask-codey.com/courses/design-patterns/topics/exercise-dp-package-tracker)

1. [Exercise: The Package Tracker](https://www.ask-codey.com/lessons/exercise-dp-package-tracker) (Journeyman): Take the depot's ticket: packages that need a signature are now held at the depot, and released again. Add the new status to a working package whose every method checks its status, without re-checking the statuses that already work, with every arrow of the state diagram tested throughout.

Source: https://www.ask-codey.com/courses/design-patterns/chapters/dp-statuses-and-routes
