Intent
An object's behavior change is represented by its member classes, which share the same super class.
Where to use & benefits
- Need to control many states without using if-else or switch statements.
- Use a class to represent a state, not a constant or something else.
- Every state has to act in a similar manner.
- Every state must be a subclass of the same super class.
- Simplify and clarify the program.
Structure

Participants
Context (ShapeContainerContext)
maintains an instance of a ConcreteState subclass that defines the current state.
State (IShapeContainerState)
defines an interface for encapsulating the behavior associated with a particular state of the Context.
Concrete State (ShapeContainerFullState, ShapeContainerEmptyState, ShapeContainerFullState)
each subclass implements a behavior associated with a state of Context
Example
In the demonstration application, the ShapeContainerContext maintains the state of the container and collaborates with the state (ShapeContainerFullState, ShapeContainerEmptyState and ShapeContainerPartialState) objects to perform the operations based on state of the shape container.
Class Diagram
