Design a cricket information system. Matches are played between teams, scorers record every ball, and fans see a live scoreboard, commentary and player statistics.
A **tournament** has **matches** between two teams of 11 players.
A match has **innings**; each innings is a series of **overs** of 6 **balls**.
A scorer records each **ball**: runs, extras, wicket, who bowled and faced.
The **scoreboard** (runs, wickets, overs) is derived from the balls.
Fans see **live scores** and **commentary**, and **player stats**.
Stage 1: Teams, players and the match
Name the participants.
The number of overs and innings depends on the format. A `Match` has two teams and a `MatchFormat` that says how many overs and innings. T20 and ODI are implementations. Format rules live in one place (**Strategy**), so adding The Hundred is one class. Test matches also have time limits; the format interface may need more methods then.
Stage 2: Innings, overs and balls
Record what happens ball by ball.
A scoreboard needs a source of truth. An `Innings` is a list of `Over`s, and each over a list of `Ball`s. Runs and wickets are computed by summing balls. Because the total is derived, correcting one ball corrects the score everywhere. Summing every ball for each read is fine per innings (about 120 balls). Cache the result and invalidate on a correction.
Stage 3: The scorer and live listeners
Push updates when a ball is recorded.
Fans see nothing until someone refreshes. `Scorer.record` adds the ball to the innings and calls every `MatchListener`. `Scoreboard` recomputes and publishes a snapshot. A new view is one more listener (**Observer**). The scorer never changes. Fan-out to millions needs a publish layer. Listeners should hand off, not do the work inline.
Stage 4: Commentary and player stats
Build more views from the same balls.
Commentary and statistics need the same events as the scoreboard. `Commentary` writes a line per ball. `PlayerStats` updates runs, balls faced, wickets and derives strike rate and average. Each view is independent and driven by the same events, so a bug in one cannot affect the score. Stats must apply a correction by subtracting the old ball and adding the new one, not by recounting all.