Browse Java Design Patterns & Enterprise Application Architecture

Context and State Classes in the State Pattern

Design Java State contexts and state types so responsibilities stay explicit and transitions remain understandable.

On this page

The main structural question in State is where responsibility sits.

The Context

The context usually owns:

  • current state
  • stable domain data
  • transition mechanics
  • external API seen by callers

The State Types

State types usually own:

  • state-specific behavior
  • permission or transition rules
  • local interpretation of operations

Review Rule

Avoid designs where the context still contains all the conditionals and the state classes become empty ceremony. If the pattern is real, the state-specific behavior should actually move.

Revised on Thursday, April 23, 2026