-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Player data clump #30
Open
raaaahman
wants to merge
15
commits into
martinsson:master
Choose a base branch
from
raaaahman:player-data-cluster
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Maybe it is dependent on the environment?
Replace player number by player reference
…e current player into a dedicated collection class This allows to move some of our test one level below
A bug was found while extending test coverage
Introduce the PlayerInfoIterator object to query data from a PlayersList without introducing mutability weaknesses
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Player Data Clump
The issue
Game:l50-53
shows an example of Data Clump: these are the players related data, and each index relates to a single player. Such indices need to be consistent across the arrays, which can eventually lead to bugs.This commit introduces a new feature: now players can leave a game while running.
As outlined in the tests from this commit, removing a player from the
Game::players
array will mismatch the remaining players with the recorded data.While this particular bug could be fixed by setting back the correct data in the
Game::remove()
method, now any changes on these data, or inclusion of a new type of data (for example, players may be assigned a color), would then need to be performed both in theGame::add()
andGame::remove()
methods. This might not be obvious to a new programmer joining the project.Introducing a data holding class
The solution would be to group all the data referring to a same player in a dedicated data holding instance, representing this player.
To perform this operation safely, a first step is to encapsulate fields for
Game::players
,Game::places
,Game::purses
andGame::inPenaltyBox
.With all the data access encapsulated, we can nowmove these fields to the
Player
class. TheGame::players
will now hold references toPlayer
instances in order to access this data.Fixing the remove method
This refactor could have been stopped there, but the following commits outlines two new bugs that may occur when implementing the
Game::remove()
method:-If a player leaves, the current player may be changed
We can benefits from our players being instances here to use a reference to the current player, instead of an integer referring to its position in an array.
Cleaning up
This could also bring an end to this refactoring, although, the encapsulation of these change of the current player offers us a good opportunity to enforce separation of concerns, by moving all the code related to selecting the current player in a dedicated collection class
This in turn gives us the opportunity to level down all of the written tests to the
PlayersList
class scope, where the player removal feature belongs.