Design a Cricket Scoreboard Application

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-02-28

Problem Statement

Design the Low-Level Design (LLD) of a Cricket Scoreboard System — similar to what is used in live matches to track and display scores, overs, wickets, player statistics, and match results.


The system should handle the real-time update of match data, track player performance, and display current match status (like total score, overs, wickets, and run rate).


The goal is to model the core object-oriented classes and interactions, not the UI or database layer.


🎯 Goal


Design a modular, object-oriented Cricket Scoreboard Application that can:


•Track runs, wickets, overs, and extras.
•Maintain detailed stats for batsmen, bowlers, and teams.
•Update and display the current match state as the game progresses.
•Handle different match formats (T20, ODI, Test).


✅ Functional Requirements


1. Match Setup


•The match involves two teams: Team A and Team B.
•Each team has:
•11 players
•A batting order and a bowling order
•The match format defines:
•Number of overs (e.g., 20, 50, or unlimited for Tests)


2. Innings Management


•A match consists of one or two innings per team depending on the format.
•System should:
•Keep track of current innings
•Switch to next innings when required


3. Ball-by-Ball Updates


•For each ball bowled:
•Runs scored (0–6)
•Wicket (if any)
•Extras (wide, no-ball, bye, leg-bye)
•Update:
•Team total score
•Batsman’s runs
•Bowler’s stats (overs, runs conceded, wickets)


4. Scoreboard Display


•Display real-time details such as:
•Total score, wickets, overs
•Current striker and non-striker
•Current bowler
•Run rate
•Partnership stats (optional)


5. End of Match Summary


•After all innings:
•Show match summary:
•Team scores
•Top performers
•Winning team and margin


⚙️ Non-Functional Requirements


•Extensible — Should easily support new formats (e.g., The Hundred).
•Maintainable — Clear separation between match logic, players, and stats.
•Accurate — No mismatch in runs, overs, or wickets.
•Real-time update capable (for simulation or integration with live feed).


🧱 Key Classes to Design


ClassResponsibility


Match


Represents the entire match — teams, innings, format, and result.


Team


Holds team name, players, and current score.


Player


Represents a player with stats (runs, wickets, etc.).


BatsmanStats


Tracks a batsman’s individual performance.


BowlerStats


Tracks a bowler’s overs, runs conceded, and wickets.


Innings


Represents a single innings — tracks overs, runs, wickets, and batsmen.


Over


Holds details of six balls.


Ball


Represents one ball event (runs, extras, wicket).


Scoreboard


Responsible for displaying or returning match summary.


MatchController


Handles game flow, like starting match, updating score, and ending innings.


🧩 Suggested Class Relationships

1 2Match 3 ├── Team teamA 4 ├── Team teamB 5 ├── List<Innings> inningsList 6 ├── MatchType type (T20, ODI, TEST) 7 ├── MatchStatus status (ONGOING, COMPLETED) 8 9Team 10 ├── String name 11 ├── List<Player> players 12 ├── int totalRuns 13 ├── int wickets 14 ├── double oversPlayed 15 16Player 17 ├── String name 18 ├── Role role (BATSMAN, BOWLER, ALL_ROUNDER) 19 ├── BatsmanStats battingStats 20 ├── BowlerStats bowlingStats 21 22BatsmanStats 23 ├── runsScored 24 ├── ballsFaced 25 ├── fours 26 ├── sixes 27 ├── isOut 28 29BowlerStats 30 ├── oversBowled 31 ├── runsConceded 32 ├── wicketsTaken 33 ├── economyRate 34 35Innings 36 ├── Team battingTeam 37 ├── Team bowlingTeam 38 ├── List<Over> overs 39 ├── int totalRuns 40 ├── int wickets 41 ├── int extras 42 43Over 44 ├── List<Ball> balls 45 ├── Bowler bowler 46 47Ball 48 ├── int runs 49 ├── boolean isWicket 50 ├── ExtraType (NONE, WIDE, NO_BALL, LEG_BYE, BYE) 51 ├── Batsman striker 52 ├── Bowler bowler


🔄 Example Flow


🧾 Scenario:


•Match Type: T20
•Teams: India vs Australia
•India bats first.


Ball 1: 1 run

Ball 2: 4 runs

Ball 3: Wicket

Ball 4: 0 run

Ball 5: 6 runs

Ball 6: 2 runs


Over Summary:


Runs = 13, Wickets = 1


Scoreboard:


India: 13/1 (1.0 overs)


🧮 Example Output

1 2{ 3 "battingTeam": "India", 4 "score": "13/1", 5 "overs": "1.0", 6 "striker": "Rohit Sharma - 7(3)", 7 "nonStriker": "Virat Kohli - 6(3)", 8 "bowler": "Starc - 1.0-13-1", 9 "runRate": 13.0 10}


🧠 Design Patterns to Use


•Observer Pattern: Update scoreboard when match data changes.
•Strategy Pattern: Handle different match formats (T20, ODI, Test).
•Factory Pattern: Create match/innings objects based on format.
•State Pattern (optional): Manage match states — STARTED, IN_PROGRESS, COMPLETED.


⚡ Possible Extensions


•Add live commentary feed support.
•Add persistence (save match progress to DB).
•Add event replay capability.
•Add Duckworth-Lewis (DLS) support for rain interruptions.
•Add leaderboard integration for tournaments.


✅ Final Summary:


Design a Cricket Scoreboard Application (LLD) that:


•Tracks runs, wickets, overs, and player stats ball-by-ball.
•Supports multiple match formats.
•Provides real-time scoreboard updates.
•Follows clean, modular OOP principles for extensibility.


Solution

Comments