LearningTech

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:
    def __init__(self):
        pass

    def execute(self):
        print('Executing State')