Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Lifecycle rules are the problem

โญโญโญ advancedโณ 10 min read๐Ÿ“ Lesson 213 of 256

Coins reset on empty; likes at exactly five; both mutators guard the same condition โ€” underline every rule sentence.

Class FRQs are won in the lifecycle rules โ€” the sentences that say when state may change:

  • "coins reset to zero when the machine is emptied" โ†’ a getter with a side effect (emptyCoins).
  • "a song becomes liked on its FIFTH play" โ†’ == 5, not >= 5 (the sixth play must do nothing).
  • "a player at 0 HP cannot be damaged or healed" โ†’ BOTH mutators guard on the same condition.
  • "restock happens even when empty" โ†’ a transition with no guard.

Underline every rule sentence; each one is one if (or one deliberate absence of an if). Then implement the class in spec order โ€” constructor first, transitions next, accessors last โ€” and re-read the rules against your ifs. A missing guard is invisible in the happy path; that is why the graders wrote hidden tests for it.