Resources‎ > ‎Programming‎ > ‎Object-Oriented Design‎ > ‎OO Tutorial‎ > ‎Lesson 7‎ > ‎

Sample Solutions

Step 1 (Facts finding)

  • play a RPS game,
  • needs at least two players,
  • There is no upper-limit on the number of players,
  • Rock : a clenched fist,
  • Paper : an open hand,
  • Scissors : two fingers extended and separated,
  • select a hand which defeats that of other players,
  • Rock blunts or breaks scissors: that is, rock defeats scissors.
  • Paper covers, sands or captures rock: paper defeats rock.
  • Scissors cut paper: scissors defeats paper.
  • When one of the following conditions is met, the game ends in draw:
    • all Rock, Paper and Scissors hands are presented, or
    • only one kind (either Rock, Paper or Scissors) is presented.

Step 2 (decide on the concept/viewpoint)

  • The game's result is decided by the three-sided content.
  • the contest is based on hands.

Step 3 modeling

First, model the relationship between a player and its hand as:

Second, model the rule, which determines the winning and loosing as:

Third, combine the above two to get the final model as:

Typical mistakes

The following is a model focused on the "game" and "player":

This model does not have a mechanism to determine the winner/looser. It also does not describe the three-sided contest.

You might be able to resolve this by simply adding the judge() function in the "Game" class. The resulting program might work, but you cannot tell how the result of the game is determined from the model.

The following model demands further generalization.