(20 points) Here's "a" solution: If your answer does not match this, don't panic!
This is just one of several possible solutions! For example, notice that
we show a player as being able to play in only one team. If your
players can play in more than one team, that is fine!
The "color" is also shown as a "set of strings" attribute; this is possible in ODL
because you have constructors such as Set, List etc. Notice that this
question was featured in the E/R chapter, where it was not possible to make
a balloon to be a set (hence the statutory statement that "a set of colors is
not a suitable attribute type for teams"). If you took this statement to heart,
you might have made color to be a separate class and expressed the uniform
colors as a relationship; that is fine! Or you could have a color as an enum
or as a struct of three reals (with proportions for the red,
blue and green percentages!). There are many posible solutions.
Finally, we have chosen a List to denote the players of a team; the reason
for this is two-fold: (i) in several sports, the players are ordered
and (ii) the captain can be easily indicated by his position on the list,
(by just an integer, get it? :-)). You could have instead chosen a Set,
in which case, captain would have been a string or something (realize
that you cannot have an attribute of type Player; so, you
would have to figure out how to enforce the requirement that the captain
is one of the players themselves) But that looks shabby, don't you
agree? Or you could make captain be a one-one relationship from Team to
Player, that
too would serve the purpose, though that still doesn't prevent us
from naming a non-player as a captain.
Obviously, we cannot enumerate every possible answer! All we look for is
to see if your solution satisfies
the question's constraints; if so, you are fine! 15 points for every correct
interface declaration with 5 more points for identifying any relevant notes.
interface Team
{
attribute string name;
attribute Set<string> colors_of_uniform;
relationship List<Player> members
inverse Player::playsfor;
attribute int captain;
relationship Set<Fan> favorite_team_of
inverse Fan::favorite_teams;
};
interface Player
{
attribute string name;
relationship Team playsfor
inverse Team::members;
relationship Set<Fan> favorite_player_of
inverse Fan::favorite_players;
};
interface Fan
{
attribute string name;
relationship Set<Team> favorite_teams
inverse Team::favorite_team_of;
relationship Set<Player> favorite_players
inverse Player::favorite_player_of;
attribute string favorite_color;
};