TypeScript State Pattern

Definition

Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.

Explanation

This pattern is used in computer programming to encapsulate varying behavior for the same routine based on an object's state object. This can be a cleaner way for an object to change its behavior at runtime without resorting to large monolithic conditional statements.

Output