Context:

"Dynamic classification": Object that receives a small number of messages, but the entire set of methods it uses to respond to them depends upon its current state.

Challenge:

  • To encapsulate state management.
  • To virtually replace an object's effective virtual table.

Skill:

Participants:

Finite State Machine (FSM):

Container of states, representing the current one. Responsible for state switching. May contain common data.

State:

The current FSM contents. The capability to actually respond to messages. Possibly, the default for some of them (e.g. to shift to next state).

Concrete State:

Encapsulates the methods for the FSM interface and possibly specific data

Signature:

FSM contains States, references the current State and interfaces for it.

Scope:

General.