mercredi 10 juin 2020

OOP: Cleanly representing player data

my app tracks many different attributes about a player (there are 1000s of players):

1) Various Scores and Ratings - after each game the player's performance ratings are updated 2) Some statistics like total games won/lost 3) Some other attributes like how much game money the person has

The simple solution is to just represent the data in a player object that has tons of member variables i.e. player.wins, player.ratingA, etc. but storing everything in one giant object seems like bad design.

Is there a OOP design pattern/strategy for this, I want to learn how to do it correctly.

My Attempt:

One idea I had was to split the attributes into several categories and have a class for each category store a map from player name -> player attributes in that category.

I.e. PlayerRatings object with UpdateRating( Player, GameResult ) and GetRating( Player ) that both calculates and stores a player's rating based on performance.

I am using an object orientated programming language (i.e. Java, C#).

Aucun commentaire:

Enregistrer un commentaire