Implementing state-specific behavior directly within a class is inflexible because it commits the class to a particular behavior and makes it impossible to add a new state or change the behavior of an existing state later, independently from the class, without changing the class. In this, the pattern describes two solutions: Define separate (state) objects that encapsulate state-specific behavior for each state. That is, define an interface (state) for performing state-specific behavior, and define classes that implement the interface for each state. A class delegates state-specific behavior to its current state object instead of implementing state-specific behavior directly.
Implementing state-specific behavior directly within a class is inflexible because it commits the class to a particular behavior and makes it impossible to add a new state or change the behavior of an existing state later independently from the class without changing the class In this the pattern describes two solutions Define separate (state) objects that encapsulate state-specific behavior for each state That is define an interface (state) for performing state-specific behavior and define classes that implement the interface for each state A class delegates state-specific behavior to its current state object instead of implementing state-specific behavior directly