Monday, April 23, 2007

State

Sometimes, the operations of an object is based on a certain state. Then the State pattern helps:

In the figure, the Request() can be different when Context has different States. And the State can be dynamically changed. The advantages are:
  • It localize the state-specific behavior and partitions operations for different states.
  • It makes state transition explicit.
  • States objects can be shared.
The creation of State objects can be managed by a pool manager if needed.

No comments: