State Pattern
The State Pattern is a behavioral design pattern that allows an object to alter its behavior when its internal state changes. This pattern encapsulates state-specific behaviors in separate classes, making it easier to manage and extend. It promotes cleaner code by avoiding large conditional statements that dictate behavior based on the object's state.
In the State Pattern, an object, often referred to as the Context, maintains a reference to a state interface. Each concrete state class implements this interface, defining its own behavior. When the state changes, the context updates its reference, allowing it to delegate behavior to the current state object seamlessly.