Polski

Behavioral patterns

State

An object's behaviour changes with its internal state, replacing sprawling conditionals.

Article

State: an object that changes behaviour with its life stage

The State pattern through an order in a pierogi place: New, Paid, InKitchen, Delivered and Cancelled as separate objects that guard the allowed transitions themselves. A state machine without an if-else ladder, code in five languages.

Related articles

Challenges

Around the topic

In this group: Behavioral patterns