android - Java classes from database architecture -
i have relatively simple database containing player
table (a single field username
) , game
(a single field date
) one. player
can take part in multiple game
, game
can played multiple player
, use many-to-many
relationship column score
added joined table store score of player
in game
.
in java code, have player
class field username
, game
1 field date
. however, not know if should create third class join table or if should add list<player>
attribute within game
class along list of list<integer>
store score.
edit: example
player
table:
player_id player_name 1 bob 2 lea 3 john
game
table:
game_id game_date 1 20/08/2017 2 19/08/2017
joined
table:
game_id player_id score 1 1 50 1 2 35 2 1 50 2 3 29
i not create separate class joined
table. go map<player, integer>
in game
class hold players in game , respective scores.
something (simple, no error checks):
class game { map<player, integer> playerscores = new hashmap<>(); void addplayer(player p) { playerscores.put(p, 0); } void incrementscore(player p, int increment) { int newscore = getscore(p) + increment; playerscores.put(p, newscore); } int getscore(player p) { return playerscores.get(p); } // etc... }
Comments
Post a Comment