Platinum Partner
java,enterprise-integration,patterns,tips and tricks

The State Pattern

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 {{ articles[0].authors[0].realName }}, DZone MVB. (source)

Opinions expressed by DZone contributors are their own.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}