guidanoli / rummy

Rummy Card Game
MIT License
2 stars 0 forks source link

hasValidState is an unnecessary method #3

Closed guidanoli closed 5 years ago

guidanoli commented 5 years ago

Basically, every implementation of the CardSequenceType interface should ensure that it always has a valid state - that is, two cards are sequential to one another (depending on what being sequential means to that specific sequence type).

Thus, the function will never output a false value because the CardSequenceBuilder and the addCard, removeCard, split methods should never leave the sequence in an invalid state.

Now, the CardSequenceBuilder may leave the sequence on an unstable state, but not on an invalid one. The difference is that one means the sequence disregards its type validation - which is never to be allowed - and the other means that the cards are sequential to one another but cannot be validated fully. Implementation-wise, a card sequence is unstable when it has less than three cards.

The solution may be remove the hasValidState from the interface and its implementations (since they won't be called either way), and its occurrence - currently only in the isStable method.