|
1 | | -# Designing a Cricket Information System like CricInfo |
| 1 | +# Cricket Information System (LLD) |
| 2 | + |
| 3 | +## Problem Statement |
| 4 | + |
| 5 | +Design and implement a Cricket Information System similar to CricInfo that provides comprehensive information about cricket matches, teams, players, and live scores. The system should handle real-time updates, match statistics, and user interactions. |
| 6 | + |
| 7 | +--- |
2 | 8 |
|
3 | 9 | ## Requirements |
4 | | -1. The Cricinfo system should provide information about cricket matches, teams, players, and live scores. |
5 | | -2. Users should be able to view the schedule of upcoming matches and the results of completed matches. |
6 | | -3. The system should allow users to search for specific matches, teams, or players. |
7 | | -4. Users should be able to view detailed information about a particular match, including the scorecard, commentary, and statistics. |
8 | | -5. The system should support real-time updates of live scores and match information. |
9 | | -6. The system should handle concurrent access to match data and ensure data consistency. |
10 | | -7. The system should be scalable and able to handle a large volume of user requests. |
11 | | -8. The system should be extensible to accommodate new features and enhancements in the future. |
12 | | - |
13 | | -## Classes, Interfaces and Enumerations |
14 | | -1. The **Match** class represents a cricket match, with properties such as ID, title, venue, start time, teams, status, and scorecard. |
15 | | -2. The **Team** class represents a cricket team, with properties like ID, name, and a list of players. |
16 | | -3. The **Player** class represents a cricket player, with properties such as ID, name, and role. |
17 | | -4. The **Scorecard** class represents the scorecard of a match, containing team scores and a list of innings. |
18 | | -5. The **Innings** class represents an innings in a match, with properties like ID, batting team, bowling team, and a list of overs. |
19 | | -6. The **Over** class represents an over in an innings, containing a list of balls. |
20 | | -7. The **Ball** class represents a ball bowled in an over, with properties such as ball number, bowler, batsman, and result. |
21 | | -8. The **MatchStatus** enum represents the different statuses of a match, such as scheduled, in progress, completed, or abandoned. |
22 | | -9. The **MatchService** class manages the matches in the system, providing methods to add, retrieve, and update match information. It follows the Singleton pattern to ensure a single instance of the service. |
23 | | -10. The **ScorecardService** class manages the scorecards of matches, allowing the creation, retrieval, and update of scorecards and their associated data, such as innings and scores. It also follows the Singleton pattern. |
24 | | -11. The **CricinfoSystem** class serves as the main entry point of the system, integrating the match and scorecard services and providing high-level methods for interacting with the system. |
| 10 | + |
| 11 | +1. **Match Information Management:** |
| 12 | + - Store and manage cricket match details |
| 13 | + - Track match schedules and results |
| 14 | + - Support real-time score updates |
| 15 | + - Handle match status transitions |
| 16 | + |
| 17 | +2. **Team and Player Management:** |
| 18 | + - Maintain team rosters and player information |
| 19 | + - Track player roles and statistics |
| 20 | + - Support team composition changes |
| 21 | + |
| 22 | +3. **Scorecard Management:** |
| 23 | + - Record detailed match statistics |
| 24 | + - Track innings, overs, and ball-by-ball information |
| 25 | + - Maintain batting and bowling statistics |
| 26 | + |
| 27 | +4. **Search and Retrieval:** |
| 28 | + - Search for matches, teams, and players |
| 29 | + - View detailed match information |
| 30 | + - Access historical data and statistics |
| 31 | + |
| 32 | +5. **System Requirements:** |
| 33 | + - Handle concurrent access |
| 34 | + - Ensure data consistency |
| 35 | + - Support scalability |
| 36 | + - Allow for future extensions |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +## Core Entities |
| 41 | + |
| 42 | +### 1. Match |
| 43 | +- **Fields:** String id, String title, String venue, Date startTime, Team team1, Team team2, MatchStatus status, Scorecard scorecard |
| 44 | +- **Methods:** updateStatus(), getScorecard(), getMatchDetails() |
| 45 | + |
| 46 | +### 2. Team |
| 47 | +- **Fields:** String id, String name, List<Player> players |
| 48 | +- **Methods:** addPlayer(), removePlayer(), getTeamStats() |
| 49 | + |
| 50 | +### 3. Player |
| 51 | +- **Fields:** String id, String name, String role |
| 52 | +- **Methods:** getPlayerStats(), updateRole() |
| 53 | + |
| 54 | +### 4. Scorecard |
| 55 | +- **Fields:** Match match, List<Innings> innings |
| 56 | +- **Methods:** addInnings(), updateScore(), getMatchSummary() |
| 57 | + |
| 58 | +### 5. Innings |
| 59 | +- **Fields:** String id, Team battingTeam, Team bowlingTeam, List<Over> overs |
| 60 | +- **Methods:** addOver(), getInningsSummary() |
| 61 | + |
| 62 | +### 6. Over |
| 63 | +- **Fields:** int overNumber, List<Ball> balls |
| 64 | +- **Methods:** addBall(), getOverSummary() |
| 65 | + |
| 66 | +### 7. Ball |
| 67 | +- **Fields:** int ballNumber, Player bowler, Player batsman, String result |
| 68 | +- **Methods:** recordResult(), getBallDetails() |
| 69 | + |
| 70 | +### 8. MatchStatus (Enum) |
| 71 | +- **Values:** SCHEDULED, IN_PROGRESS, COMPLETED, ABANDONED |
| 72 | + |
| 73 | +--- |
| 74 | + |
| 75 | +## Services |
| 76 | + |
| 77 | +### 1. MatchService (Singleton) |
| 78 | +- **Methods:** |
| 79 | + - addMatch(Match match) |
| 80 | + - getMatch(String id) |
| 81 | + - updateMatchStatus(String id, MatchStatus status) |
| 82 | + - searchMatches(String query) |
| 83 | + |
| 84 | +### 2. ScorecardService (Singleton) |
| 85 | +- **Methods:** |
| 86 | + - createScorecard(Match match) |
| 87 | + - updateScorecard(String matchId, Scorecard scorecard) |
| 88 | + - getScorecard(String matchId) |
| 89 | + - addInnings(String matchId, Innings innings) |
| 90 | + |
| 91 | +### 3. CricinfoSystem |
| 92 | +- **Methods:** |
| 93 | + - getMatchDetails(String matchId) |
| 94 | + - getTeamDetails(String teamId) |
| 95 | + - getPlayerDetails(String playerId) |
| 96 | + - search(String query) |
| 97 | + |
| 98 | +--- |
| 99 | + |
| 100 | +## Example Usage |
| 101 | + |
| 102 | +```java |
| 103 | +CricinfoSystem system = CricinfoSystem.getInstance(); |
| 104 | + |
| 105 | +// Create a new match |
| 106 | +Match match = system.createMatch("IND vs AUS", "Melbourne Cricket Ground", new Date()); |
| 107 | + |
| 108 | +// Update match status |
| 109 | +system.updateMatchStatus(match.getId(), MatchStatus.IN_PROGRESS); |
| 110 | + |
| 111 | +// Record a ball |
| 112 | +system.recordBall(match.getId(), 1, 1, "FOUR"); |
| 113 | + |
| 114 | +// Get match details |
| 115 | +MatchDetails details = system.getMatchDetails(match.getId()); |
| 116 | +``` |
| 117 | + |
| 118 | +--- |
| 119 | + |
| 120 | +## Demo |
| 121 | + |
| 122 | +See the demo class for a sample usage and simulation of the cricket information system. |
| 123 | + |
| 124 | +--- |
| 125 | + |
| 126 | +## Extending the Framework |
| 127 | + |
| 128 | +- **Add user authentication:** Support for user accounts and preferences |
| 129 | +- **Add commentary system:** Real-time match commentary |
| 130 | +- **Add statistics engine:** Advanced player and team statistics |
| 131 | +- **Add notification system:** Match updates and alerts |
| 132 | +- **Add social features:** User comments and discussions |
| 133 | + |
| 134 | +--- |
| 135 | + |
| 136 | +## Design Patterns Used |
| 137 | + |
| 138 | +- **Singleton Pattern:** For service classes (MatchService, ScorecardService) |
| 139 | +- **Factory Pattern:** For creating matches and scorecards |
| 140 | +- **Observer Pattern:** For real-time updates and notifications |
| 141 | +- **Strategy Pattern:** For different types of match formats |
| 142 | + |
| 143 | +--- |
0 commit comments