We need to create validators for each status. The validator will check if transition from current state is allowed or not. 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
class WorkflowExecutionValidator(object): def __init__(self, workflow_execution: WorkflowExecution): self.workflow_execution = workflow_execution def validate(self): validators = [ InitialValidator(), ProcessingValidator(), FailedValidator(), CompletedValidator() ] for validator in validators: if validator.is_validator_for(self.workflow_execution): return validator.validate(self.workflow_execution)