 |
 |
 |

The state design pattern is a behavioural pattern that allows the programmer to implement state changes, much like those in a finite state machine easily. Using the state design pattern will allow the object to change its behaviour depending on it's internal state at run-time. Therefore, the object will remain the same, but how it behaves is now different.

There are many possible uses for this design pattern.
- Changing the state of a file between Read Only/Read and Write
- Changing the status of a account (bank, video store, library) depending on a factor (balance, unreturned books/videos etc)
- Changing the emotion of a character in a game between happy/sad/angry etc.

Easier to implement as compared to say, using case or conditional statements to switch between different states.

It is difficult to implement non-deterministic state machines.

There are four patterns that are related to the state pattern. These are the flyweight pattern, the mediator pattern, the objectifier pattern, and the singleton pattern.
- The state pattern is a form of the objectifier pattern
- The flyweight pattern can be used to share different state object.
- Often, the state pattern is paired with the mediator pattern when creating user interfaces.
- The singleton pattern allows you to implement states that are nonparametric.
|
 |
 |
 |