We need to create validators for each status. The validator will check if transition from current state is allowed or not. All validators are injected into WorkflowExecutionValidator. private List<Validator> validators WorkflowExecutionValidator will pick up an appropriate validator from a list and check if transition is allowed. Validators are implemented for each workflow execution status Validators are applied in production code
public class WorkflowExecutionValidator { private List<Validator> validators; public boolean isValid(WorkflowExecution workflowExecution){ //the validator to be used is selected based on the status Validator validator = validators.stream().filter(validator -> validator.isFor(workflowExecution.getStatus())).findFirst().orElseThrow(() -> new RuntimeException("Could not find a validator for status " + workflowExecution.getStatus())); return validator.isValid(workflowExecution); } }