That would work, however you have some issues with your design and what you described.
- In transitioning to each state rules need to be fired and validate input object - your design does not cover this
- State changing is not managed anywhere so you are going to scatter that logic in your StateFacotry or elsewhere and handle it manually.
What I would to is creating a StateMachine class that you can simply call Transition method and provide a target State. The transition method queries from State to know what rules need to be validated and calls validation method. If successful then it changes the state of object.
Benefit of this design:
- StateMachine can register a graph of state (S1->S2,S3 | S2->END | S3->S4 | S4->END)
- State transitioning happens automatically based on register graph and
- Each State knows what are the required rules to be met to allow the transition happens successfully. (Self-descriptive)
- StateMachine has not exposed the logic how the states are transitioning and all encapsulated in that implementation
- StateMAchine is independent of what the actual object is and manages all the transition logic plus validation execution (that you can simply integrate a full-fledged validation engine into your state machine)