I have a state machine that will collect/generate data at different states and the data will then be used in some later state again. How do I transfer the data between states?
Both options seem ugly to me, is there a better one? Or maybe I should use another pattern instead of a state machine?
Motivation: The problem I'm trying to solve is to process a long text file where each line starts with a numeric id followed by data.
You can use Java Enum to do this. Basically, you may pass a state and a symbol (or event) to the new state. And in that case declaring states and symbols as enums will solve your problem by making it type-safe and easy too. The below link will help you.