I have recently started working on a project where we have a workflow engine which has flexibility to add dynamic states and corresponding actions for each state and all these are stored in database.
Workflow Name: Make breakfast
Workflow ID : 143
state 1 : Turn on stove
state Id 1121
state 2 : make breakfast
state Id 1122
and then there are actions that user can perform when in each state
Action Name: Approve
Action Id: 0098
Action Name: Reject
Action Id: 0099
Now the code works by using amazing if else statements and mapping everything to enums which is a mess.
I was thinking of applying strategy pattern to fix the issue but then we cannot as everything is dynamic here. we can have n number of workflows,states and actions.
what is the best way to tackle this issue?
The major problem is that we have to manually add the id of corresponding states,actions in side the enum which means that it will change with each environment too. And we have to use if state == enumofstate then do this else do that
What I am looking for, may be, is something like "state machine pattern" but dynamic, is there anything like that?