
TypeScript 4 Design Patterns and Best Practices
By :

The State pattern deals with state management concerning a particular object and, more specifically, how to make an object behave differently based on its inner state. You have an object similar to the Originator
object that you learned about in the Memento pattern. Then, at runtime, you change its internal state and the object will behave differently when used by the client.
You can think of this pattern as having a state machine that changes the behavior of an object when its internal state changes. Because you will be placing logic statements based on the object's state parameter, it is useful if you want to implement inheritance without actually defining subclasses.
We'll explain in detail when to use this pattern.
You can use the State pattern in the following cases: