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.
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 theCardSequenceBuilder
and theaddCard
,removeCard
,split
methods should never leave the sequence in an invalid state.Now, the
CardSequenceBuilder
may leave the sequence on anunstable
state, but not on aninvalid
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 theisStable
method.