Many objects behave differently depending on where they are in their life. An order that is not yet paid can be paid or cancelled. An order that has shipped can only be delivered. The same method call, cancel(), should work in one case and be refused in the other.
The usual first version of this code is a status field plus a switch statement in every method. Each method asks "what state am I in?" and branches. With five states and four events, that is twenty cases spread across four methods. Adding a state means editing every one of them.
The State pattern is one of the 23 patterns in the 1994 Gang of Four book. Its intent is to let an object alter its behavior when its internal state changes, so that the object appears to change its class. It is a behavioral pattern, one of the group about how objects share work.
It has three roles. The context is the object the rest of the program talks to, here the order. The state interface lists every event the context can receive. Each concrete state is one class that implements that interface for one state. The context holds a reference to its current state object and passes every event to it. When a transition happens, the context swaps that reference for a new state object.