Boost your focus and productivity using the Pomodoro technique.
A Pomodoro timer is more complex than a standard stopwatch because it automatically transitions between different phases: Focus, Short Break, and Long Break.
If you try to manage this with isolated boolean variables (e.g., isFocus = true, isBreak = false, isRunning = true), your code will quickly become a nightmare of conflicting states.
Professional applications solve this using a Finite State Machine (FSM). In an FSM, the application can only be in exactly one predefined state at any given time.
For a Pomodoro timer, the states might be: IDLE, FOCUS_RUNNING, FOCUS_PAUSED, BREAK_RUNNING, or BREAK_PAUSED.
When a timer hits zero, the FSM receives a TICK_COMPLETE event. Based on its current state (e.g., FOCUS_RUNNING) and its Pomodoro count (e.g., 4th session completed), it cleanly transitions to the exact next state (e.g., LONG_BREAK) without checking dozen of messy boolean flags.
Developed by Francesco Cirillo, the technique uses a timer to break work into intervals, traditionally 25 minutes in length, separated by short breaks. The method is based on the idea that frequent breaks can improve mental agility.
Why is a Finite State Machine (FSM) better than using multiple boolean variables (true/false) to track an app's status?