Design Example: A chess application

We’ll be designing a chess application’s model.

Models

Board
A board maintaining a list of the pieces and their locations.
Piece
A piece of the board. It knows what board it is in, and what its coordinates are.
Move
Identifies a “move”. It should contain information about “color”, i.e. whose move it is, as well as what the move is, in the form of a piece object to move, and where to move it to.
Game
The model representing an overall game. It must have a board associated with it, and keep track of a series of moves and whose turn it is.

A main decision is where the logic goes for knowing if a move is valid, if the king is in check, etc. We will put that logic mostly in the Game class.

Board

Needs to know about

Instance variables

These are meant to be private, but we probably won’t enforce it. Users should not access these directly

Class Methods

Instance Methods

Piece

Needs to know about

Nothing else.

Instance Variables

Class Methods

Instance Methods

Move

Moves will essentially implement the command pattern.

Needs to know about

Nothing.

Instance Variables

Class Methods

Instance Methods

Game

Needs to know about

Instance Variables

Class Methods

Instance Methods

MovesList

Maintains a list of “moves” with undo-redo functionality built in.

Needs to know about

Nothing. If desired, we could use a separate DoubleLinkedList implementation, and adjust its interface. Or we could bake the idea of a double-linked list in it.

Instance Variables

Class Methods

Instance Methods

Unresolved Issues