State Design Pattern

State Design Pattern is also one of the Behavioral Design Patterns. As per the behavioural design pattern, the state design pattern solves the problems of sharing responsibilities between objects. The aspect behind this pattern is the change of behaviour of the object on the change of state. State design pattern also follows the “Open for extension but Closed for modification” coding principle.

Considering design pattern solves many problems, for example, state design pattern helps you to avoid many if/else conditions because deciding the scenario (set of code statements) based on multiple conditional statements and also need to verify the object state, for example, an object with different states and state is decided based on a set of conditional statements adding chaos in your code. Using the state design pattern, we create multiple concrete state classes (implementations) and decides on runtime which concrete state implementation is going to run.

As per the state design pattern, context is responsible to delegates the client request to the current state implementation.

Leave a Reply

Your email address will not be published. Required fields are marked *