Java Code Samples

State

Posted in Old stuff by Cristian on October 5, 2011

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:

Code sample:

About these ads
Tagged with: , ,

One Response

Subscribe to comments with RSS.

  1. [...] State [...]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: