2.4 Composition and decomposition
To see composition in action, we’ll look at a few, isolated elements of the design of a chess game.
A game of chess is played between two players, using a chess set featuring a board containing 64 positions in an grid. The board can have two sets of 16 pieces that can be moved in alternating turns by the two players in different ways. Each piece can capture other pieces. The board will be required to draw itself on the computer screen after each turn.
We’ve identified some of the possible objects in the description using italics, and a few key methods using bold. This is a common first step in turning an object-oriented analysis into a design. At this point, to emphasize composition, we’ll focus on the board, without worrying too much about the players or the different types of pieces.
The chess set is composed of a board and 32 pieces. The board further comprises 64 positions. The positions are commonly...