Comparison
State machinevsState pattern
State machine
you wrote down every state and every allowed move between them, and three combinations you had shipped turned out to be impossible.
A model of an object as a fixed set of states plus the transitions permitted between them, usually recorded as a table or a diagram. Making it explicit is the highest-value modelling move available for anything with a lifecycle — an order, a subscription, a deployment — because the illegal transitions become visible instead of implied. The state pattern is one way to implement it; a table and a switch is often the clearer one.
Full entry →State pattern
the object's behaviour changed after a call and nothing branched — it had swapped the object it was delegating to.
Representing each state of an object as a separate class implementing a shared interface, with the object delegating to its current one. It looks structurally identical to strategy, and the difference is who does the choosing: a strategy is handed in by the client and stays, a state replaces itself as the object moves through its lifecycle. That self-transition is the whole distinction and the whole interview answer.
Full entry →