Problem Statement
Explain how the Command pattern helps implement undo and audit in a workflow engine.
Explanation
Command wraps an action as an object with execute and optional unexecute. You can queue, log, and replay these objects. This gives you a clear history for audit and a way to reverse certain actions.
In a workflow engine, each step becomes a command. You persist commands to durable storage, then rehydrate and re-run after crashes. For undo, each command stores minimal state needed to roll back safely.
Code Solution
SolutionRead Only
interface Command{ exec(); undo(); }
log.append(command.serialize());