Intent

An object's behavior change is represented by its member classes, which share the same super class.

Where to use & benefits

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


Source Code Links