Developer’s toolbox: 💢 State Design Pattern

Vee Lesyk
Dots and Spaces
Published in
1 min readSep 1, 2019

It lets you change the behavior of a class when the state changes.

Wikipedia says:

The state pattern is a behavioral software design pattern that allows an object to alter its behavior when its internal state changes. This pattern is close to the concept of finite-state machines. The state pattern can be interpreted as a strategy pattern, which is able to switch a strategy through invocations of methods defined in the pattern’s interface.

Github repo: link.

Swift

State.swift

TypeScript

State.ts
State

P.S. We would be happy to see comments according to mistakes & typos.

--

--

Vee Lesyk
Dots and Spaces

#h+ #livemoredomore Adventurer. Unique experience wizard. Maker of things. Convergence commander. Information warlock. Problem solver. System: ☉; Planet: ♁.