Design a Card Game
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2022-02-18
Problem Statement
Design the Low-Level Design of a Card Game. The system should model a standard deck of cards, players, and game flow. The design should be extensible enough to support different card games (e.g., Poker, Blackjack, Rummy, Solitaire) by reusing common components.
Functional Requirements
1.Deck Management
•Represent a standard 52-card deck (suits: ♥ ♦ ♣ ♠, ranks: 2–10, J, Q, K, A).
•Support shuffle, draw, reset operations.
2.Player Management
•A player should have an ID, name, hand of cards, score.
•Support multiple players (2–6 depending on the game).
3.Game Flow
•Start game → shuffle deck → distribute cards.
•Play rounds: draw, discard, or play cards based on rules.
•End game: decide winner based on scoring rules.
4.Extensibility for Different Games
•Each game (Blackjack, Poker, Rummy) should define its own rules for:
•Number of cards per player.
•Scoring system.
•Winning conditions.
Non-Functional Requirements
•Extensibility → Add new games without rewriting core deck/player logic.
•Modularity → Separate concerns (Deck, Player, Game, RulesEngine).
•Maintainability → Use clear abstractions for reusable logic.
Design Hints
•Core Classes:
•Card → suit, rank.
•Deck → collection of cards, shuffle, draw.
•Player → id, name, hand (list of cards).
•Game (abstract) → start(), playTurn(), end().
•BlackjackGame, PokerGame (extend Game).
•RulesEngine → encapsulates scoring & winning logic.
•Design Patterns:
•Factory Pattern → instantiate different card games.
•Strategy Pattern → for scoring/winning logic.
•Observer Pattern (optional) → notify players of moves.
✅ Example
"Design the classes for a generic Card Game. Show how you would support Blackjack and Poker without rewriting the core logic for deck or players."