flâneur — a map of the web's best reading

State

refactoring.guru · 1,955 words · saved by 1 readers

State is a behavioral design pattern that lets an object alter its behavior when its internal state changes. It appears as if the object changed its class. The State pattern is closely related to the concept of a Finite-State Machine . Finite-State Machine. The main idea is that, at any given moment, there’s a finite number of states which a program can be in. Within any unique state, the program behaves differently, and the program can be switched from one state to another instantaneously. However, depending on a current state, the program may or may not switch to certain other states. These switching rules, called transitions, are also finite and predetermined. You can also apply this approach to objects. Imagine that we have a Document class. A document can be in one of three states: Draft, Moderation and Published. The publish method of the document works a little bit differently in each state: Possible states and transitions of a document object. State machines are usually impleme

/ Design Patterns / Behavioral Patterns State Intent State is a behavioral design pattern that lets an object alter its behavior when its internal state changes. It appears as if the object changed its class. Problem The State pattern is closely related to the concept of a Finite-State Machine Finite-State Machine: https://refactoring.guru/fsm . Finite-State Machine. The main idea is that, at any given moment, there’s a finite number of states which a program can be in. Within any unique state, the program behaves differently, and the program can be switched from one state to another instantan

Explore this link on the map →

related reading