Co-Author of OCP Java SE 8 Programmer II Exam Guide
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Elisabeth Freeman:
If every one of your states can potentially change state to every other state, then you're kind of stuck adding code whenever you add a new state. However, it is highly unlikely that *every* state is possible from *every other* state.
Did you do a state diagram before you started to see which state transitions are atually possible?
Then, make each state responsible for determining which states are possible next.
Seems to me that, for instance, draft -> completed is possible, but not draft->approved.
In that case you only need one method in Draft State - it changes to completed. And the Draft State itself is responsible for determining the conditions when it switches state to completed. Your client does not change the state, rather the state itself changes the state.
Hope this helps,
Elisabeth
Regards,
Pho
If I create a "changeState()" method, then the method would still require the checking of old state versus new state and is it allowed.