Behavioral

State

Description

Lets an object alter its behavior when its internal state changes. It appears as if the object changed its class.

Where to use

  • Workflow engines.
  • \n
  • TCP Connections.
  • \n
  • Game Character States.

Real World Example

A Phone. If 'Unlocked', pressing buttons calls numbers. If 'Locked', pressing buttons turns on the screen.

Code Example

class State:\n    def __init__(self):\n        pass\n\n    def execute(self):\n        print('Executing State')