0
0
LLDsystem_design~12 mins

Piece movement rules (polymorphism) in LLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Piece movement rules (polymorphism)

This system models the movement rules of different game pieces using polymorphism. Each piece type (like pawn, rook, knight) has its own movement logic encapsulated in separate classes. The system allows easy extension and clear separation of movement behaviors.

Architecture Diagram
User
  |
  v
Game Controller
  |
  v
Piece (abstract class/interface)
  |         |          |          |
Pawn     Rook      Knight     Bishop
  |         |          |          |
Movement Logic (overridden methods)
  |
Board
  |
Move Validator
  |
Game State
Components
User
actor
Interacts with the game by making move requests
Game Controller
service
Receives user input and coordinates piece movement validation
Piece (abstract class/interface)
component
Defines the common interface for all piece movement rules
Pawn
component
Implements pawn-specific movement logic
Rook
component
Implements rook-specific movement logic
Knight
component
Implements knight-specific movement logic
Bishop
component
Implements bishop-specific movement logic
Board
component
Represents the game board and current piece positions
Move Validator
service
Checks if a move is valid according to piece rules and board state
Game State
component
Maintains the current state of the game including turn and piece positions
Request Flow - 8 Hops
UserGame Controller
Game ControllerPiece (abstract class/interface)
Piece (abstract class/interface)Specific Piece Implementation (e.g., Pawn, Rook, Knight, Bishop)
Specific Piece ImplementationMove Validator
Move ValidatorBoard
Move ValidatorGame Controller
Game ControllerGame State
Game ControllerUser
Failure Scenario
Component Fails:Move Validator
Impact:Invalid moves may be accepted or valid moves rejected, breaking game rules
Mitigation:Implement thorough unit tests for move validation logic and fallback to default deny on error
Architecture Quiz - 3 Questions
Test your understanding
Which component is responsible for defining the common interface for all piece movement rules?
APiece (abstract class/interface)
BGame Controller
CMove Validator
DBoard
Design Principle
This design uses polymorphism to encapsulate different piece movement rules in separate classes, promoting code reuse and easy extension. The system cleanly separates concerns: user input handling, movement logic, validation, and game state management, which improves maintainability and scalability.