Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making the domain-model of tic tac toe

Tags:

java

c#

oop

uml

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.

  1. I'm not sure about defining both a Tile and a Tile State. Maybe I should only define a Tile and have the 3 possible states specialize from it?
  2. I'm not sure what is best: to have both Player O and Player X be associations with Tic Tac Toe or have them inherit from Player that is associated with Tic Tac Toe. Following the design shown on the pic, in theory we could have a Tic 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?

Thanks

like image 548
devoured elysium Avatar asked Jun 07 '10 22:06

devoured elysium


2 Answers

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.

like image 190
bbudge Avatar answered Nov 01 '22 03:11

bbudge


To your diagram:

  1. 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.)
  2. 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.

like image 1
Gabriel Ščerbák Avatar answered Nov 01 '22 02:11

Gabriel Ščerbák