State Pattern is a #Design Pattern which allows an object to alter its behaviours based on its internal state changes. It is not possible to establish such operations without the design pattern due to the immutability of a running object. By following the design pattern, the object could be able to change its behaviour according to the state change during its lifetime and be extended with new states without affecting the existing states.
Implementing the State Pattern onto a class could be done by encapsulate each state of the class into another independent class which will be in composition of the old class. The old class will change its state via a superclass of the state classes which provides an abstraction over different kind of states that the class could go through. The superclass should be the parent for the newly created state classes.