๐ WAYPOINT LESSON
Objects are state machines
โญโญโญ advancedโณ 10 min read๐ Lesson 189 of 256
Fields are state, methods are transitions; the FRQ2 shape is one guard, one boundary, one accessor.
An object is a state machine: fields are the state, methods are transitions, constructors set the start state. Exam FRQs hide a state machine behind a story (parking garage, scoreboard, vending machine), and the rubric cares about exactly three things:
- The transition rule is the whole problem.
arrivereturns false when full โ one comparison decides three test cases. - Order of checks matters: is a duplicate plate rejected before or after the capacity check? The spec's sentence order is the check order.
- Derived state (
count(),isFull()) must be computed from the real state, never stored twice โ a second copy of the truth will drift.
The classic FRQ2 shape: constructor stores parameters (with this.),
one boolean-returning transition with a guard, one mutator that
reaches a boundary (depart on empty โ false), and one accessor.
Every graded behavior is one of those four.