Courses / Machine Coding and Low-Level Design in TypeScript / Chapter 26
Module 10 · Design problems VII: airlines, cricket and careers · Chapter 26 of 28
Live Cricket Scores: Innings, Overs, Ball-by-Ball Events and Commentary
Builds on Solving a Design Problem: Requirements to Tested Code in Six Steps and Design Patterns in TypeScript: Creational, Structural and Behavioural. Next up: Professional Network: Profiles, Connections, Jobs and Search.
Part 1 · Requirements
What the scoring system must do
A cricket scorer enters one delivery at a time, and everything a follower sees, from the scorecard to the run rate, follows from that list. This chapter builds the scoring core for a local T20 league with two clubs, Harbour XI and Lakeside XI.
A requirement is a sentence about the system that someone can check. Functional requirements say what the system does, and we write them before any class exists. For the league they are these.
- A match is between two teams of eleven. A toss decides who bats first. Each team bats one innings, which has a fixed number of overs.
- An over is six valid balls bowled from one end, and the next over is bowled from the other end by a different bowler.
- The scorer enters each delivery as it happens: the bowler, the runs off the bat, any extra and any wicket.
- The extras are wides, no-balls, byes and leg byes. A wide and a no-ball each add a run to the score and do not count as one of the six balls.
- The system keeps the scorecard: the team total, wickets and overs, each batter's runs and balls, each bowler's overs, runs and wickets, and the extras.