Skip to content
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

Solution 2-6 players: create one constructor for every possible number of players #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

martinsson
Copy link
Owner

@martinsson martinsson commented May 9, 2018

It used to be possible to construct a game with less than two players and with more than six players
however at runtime things did not work out. There was also no validation that the game was in a
playable state. The user had to come up with the idea to call the isPlayable method.

In this version it will not compile for anything other than 2-6 players. The Game class can only be
instantiated it the correct way, and the user gets immediate feedback from the compiler on any
usage errors.

Granted this type of technique becomes awkward when the number of constructors grows big, in those
cases we revert back to a more traditional strategy of runtime validations in the constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant