State

Intent

Allow an objet to alter its behavior when its internal state changes.  The object will appear to change its class.

      -Design Patterns, GoF

 

 

Structure

From dofactory.com:

 

 

Questions

1. What problem does the State pattern solve? 

2. What is a good sign that it may be useful?

3. Where can the state transitions be defined?  In the concrete state?  In a lookup table?  What are the trade-offs.

4. Should concrete state objects be cached? 

5. Do all concrete states need to be able to handle the same events (i.e. offer same behavior)?

6. How many states could necessitate using the State pattern?

7. How does the State interact with its context?

 

Examples – Which are States?

1. ??

 

 

References

·         Using the STATE Design Pattern in Java, Steven John Metsker (Informit.com, August 2002)

·         State Design Pattern (DoFactory.com)