O'Reilly logo

Swift 2 Design Patterns by Julien Lange

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The state pattern

In the state pattern, a class behavior changes based on its state. This type of design pattern comes under the behavior pattern.

In the state pattern, we create objects that represent various states and a context object whose behavior varies as its state object changes.

Role

The role of this pattern is to adapt its behavior depending on the internal state of an object. It can be used when implementing the dependency of the state object if the condition statement becomes complex.

Design

The generic class diagram structure of the state pattern is as follows:

Design

Participants

The participants in the state pattern are as follows:

  • StateMachine ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required