Making the domain-model of tic tac toe
I am trying to make the domain model of a Tic Tac Toe game. I'll try then to go on through the various steps of the Unified Process and later implement it in some language (C# or Java).
I'd like to have some feedback if I'm going on the right path: alt text http://dl.dropbox.com/u/6187267/shooterpics/tictactoedm.jpg
I've defined the game with two actors, Player O
and Player X
.
- I'm not sure about defining both a
Tile
and aTile State
. Maybe I should only define aTile
and have the 3 possible states specialize from it? - I'm not sure what is best: to have both
Player O
andPlayer X
be associations withTic Tac Toe
or have them inherit fromPlayer
that is associated withTic Tac Toe
. Following the design shown on the pic, in theory we could have aTic Tac Toe
concept with 2 Player O's, which wouldn't be correct. What is your opinion on this?
Also, am I missing something in the diagram? Although I can't see any other actors for Tic Tac Toe, should I have any other?
T开发者_如何学运维hanks
An alternative class decomposition would be to replace Board and Tile with Game and Move. A game would contain a legal series of Moves, and a Move would contain the square coordinates (or some other identifier) and whether it was player O or X. This scheme holds a little more information allowing the game can be replayed and backed up.
To your diagram:
- is constituted by should be composition relation, not association (Tiles cannot exist on their own, the state of Board is defined by the state of its Tiles.)
- Player O and Player X are instances of the Player class, not subclasses (Player 0 and Player X have same structure as Player, they have same behaviour, the difference is in identity and state - name in your diagram)
When you are talking domain model (in context of UP), you should forget about creating a software system and include only what is important for the domain of the tic tac toe game. Think of how any game is described - it has its rules (preparation, turns, game end conditions, ...), players (with identity for more games, points, owned/controlled components, roles ...) and physical components (boards, tokens, figures, cards...). If you accept those elements to be part of the domain model for games and therefore metamodel for your tic tac toe game, you should use elements, which are instances of that elements.
精彩评论