...

/

Untitled Masterpiece

Learn to create a class diagram for the chess game using the bottom-up approach.

In this lesson, we’ll create the class diagram for the Online Chess game. We’ll follow a bottom-up approach: design the simplest components and build up to the core game classes, showing relationships and responsibilities throughout.

Components of chess

As mentioned earlier, we’ll follow the bottom-up approach to designing a class diagram for the chess game.

Box

A Box represents a position on the 8x8 chessboard, defined by a row and column (0–7). It may either be empty or occupied by a chess piece.

Press + to interact
The class diagram of the Box class
The class diagram of the Box class

Chessboard

The Chessboard models the 8x8 grid of Boxes. It maintains the current state of the game, including all pieces and their positions. The board is responsible for resetting and updating itself according to the moves played.

Press + to interact
The class diagram of the Chessboard class
The class diagram of the Chessboard class

Piece

A Piece represents any chess piece (King, Queen, Rook, Bishop, Knight, or Pawn) with a color (black or white) and an “alive” or “captured” status.

  • King, Queen, Rook, Bishop, Knight, Pawn are subclasses of Piece, each implementing its specific movement logic and special rules (e.g., castling for King/Rook, en passant and promotion for Pawn).

Press + to interact
The class diagram of the Piece and its derived classes
The class diagram of the Piece and its derived classes

Move

A Move represents the transfer of a piece from one Box to another, possibly capturing an opponent’s piece. The Move tracks information such as the source and destination Boxes, the moved piece, any captured piece, and whether the move resulted in special ...