Here is the Factual that models the problem and makes the unit tests pass:
fact User {
    string userName;
    Player* players {
        Player p : p.user = this

fact Game {

fact Player {
    User user;
    Game game;

You might be tempted to add a reference from Game to Player, but this would be backwards. A Player is a role that a User plays within a Game. The User and the Game must exist first. They are predecessors. The Player is the successor.

If you forgot to make a Game unique, then the last unit test failed. Without the "unique" keyword, there could be only one Game in the system.

A Player, on the other hand, can already be distinguished from other Players by its key fields. A User takes on the role of Player in a Game. He cannot take on that role twice within the same game. For extra credit, write a unit test to verify that.

Next: Lesson 2a: Partial classes

Last edited May 15, 2011 at 3:29 AM by MichaelLPerry1971, version 3


No comments yet.