State design pattern
The State design pattern encapsulates state-specific behavior in separate representations and delegates an object's behavior according to its current state.
Object-Oriented Software Design in C++
A behavioral design pattern that encapsulates state-specific behavior in separate objects and delegates behavior according to an object's current state.
- How it is used
- Models objects whose runtime behavior and allowed transitions depend on their current state.
- How deep it goes
- Explains centralized conditionals, state subclasses, polymorphic delegation, shared data, and returned transition objects.
- Examples
- Uses an automatic ticket machine with card validation, ticket purchase, invalid actions, and sold-out behavior.
- What you can do after
- Build it from scratch by separating state-specific actions into polymorphic classes and returning objects for state transitions.
Read how Object-Oriented Software Design in C++ explains state design pattern →
Software Design for Python Programmers
The State Design Pattern is a behavioral design pattern that allows an object to alter its behavior when its internal state changes by delegating state-specific behavior to separate state representations.
- How it is used
- Manages runtime states when an object's behavior and transitions depend critically on its current state.
- How deep it goes
- Explains the pattern through a conditional implementation, a polymorphic refactoring, a generic model, and a pattern comparison.
- Examples
- Uses an automatic ticket machine with READY, VALIDATING, TICKET_SOLD, and SOLD_OUT states.
- What you can do after
- Build it from scratch by separating state classes, delegating actions, and returning objects representing the next state.
Read how Software Design for Python Programmers explains state design pattern →
What to know first
- data structureA data structure is an organized representation of data and its relationships that supports defined operations for storing, accessing, or modifying it.
- atomic typeAn atomic type is a type whose supported accesses and operations are indivisible with respect to concurrent execution and provide defined synchronization semantics.
- stateState is information describing the condition or configuration of a system or computation at a particular time that may influence its behavior or subsequent transitions.
Related concepts
- design patternkind of · A design pattern is a reusable, general solution structure for a recurring software design problem.
- stateuses · State is information describing the condition or configuration of a system or computation at a particular time that may influence its behavior or subsequent transitions.
- state transitionuses · A state transition is a change from one defined state of a system, object, or process to another according to an action, event, condition, or rule.
- behavioruses · Behavior is the observable actions, responses, outputs, or effects of a system or object under specified conditions or interactions.
- patternkind of · A pattern is a reusable approach to solving a recurring problem within a particular context.
Questions about state design pattern
What is state design pattern?
The State design pattern encapsulates state-specific behavior in separate representations and delegates an object's behavior according to its current state.
Which Manning books explain state design pattern?
Object-Oriented Software Design in C++ and Software Design for Python Programmers.
What should I know before learning state design pattern?
Manning books that teach state design pattern usually introduce credit card, data structure, atomic type and state first.
What is state design pattern a kind of?
State design pattern is a kind of design pattern. A design pattern is a reusable, general solution structure for a recurring software design problem.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

