Enterprise Integration Zone is brought to you in partnership with:

Cristian Chiovari is a Senior Software Engineer specialized in developing enterprise software applications with experience on software integration and messaging. His expertise include helping clients build software using industry best practices, Test Driven Design, Weblogic, Oracle Service Bus , Spring Frameworks, JEE. Performance improvements is something that is really passionate about and considers software development not only his job but also his main hobby. Cristian is a DZone MVB and is not an employee of DZone and has posted 10 posts at DZone. You can read more from them at their website. View Full User Profile

The State Pattern

10.19.2012
| 4147 views |
  • submit to reddit

Description:

The State pattern allows an object to alter its behavior when its internal state changes

Benefits:

  • Localizes state-specific behavior and partitions behavior for different states
  • Makes state transitions explicit

When to use:

  • An object’s behavior depends on its state, and it must change its behavior at run-time depending on that state.
  • Operations have large, multipart conditional statements thatdepend on the object’s state.

Diagram:


Published at DZone with permission of Cristian Chiovari, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)