State Design Pattern
Deep dive into the State Design Pattern with real-world examples
The State Pattern is ideal for scenarios where an object's behaviour changes dramatically based on its internal state.
This is like a real life example wherein you are using something which is related to cards and sometimes you have some invalid card or a card is blocked. So that's where you get the transaction to be declined. So this is where the state pattern is used in card system design or transactional system design.
It extracts state-specific behaviours into separate state classes. The main context object Card maintains a reference to its state object and delegates requests to it.
State: The Conceptual Model:

State: Initial Active State Example

// State: Activeclass ActiveState implements CardState { @Override public void processTransaction(Card card) { System.out.println("Active: Transaction approved."); } @Override public void blockCard(Card card) { System.out.println("Active: Blocking the card..."); card.setState(new BlockedState()); } @Override public void reissueCard(Card card) { System.out.println("Active: Direct reissue not allowed. Block the card first."); }}// State: Blockedclass BlockedState implements CardState { @Override public void processTransaction(Card card) { System.out.println("Blocked: Transaction declined. Card is inactive."); } @Override public void blockCard(Card card) { System.out.println("Blocked: Card is already blocked."); } @Override public void reissueCard(Card card) { System.out.println("Blocked: Reissuing new card..."); card.setState(new ReissuedState()); }}// State: Reissued (Terminal State)class ReissuedState implements CardState { @Override public void processTransaction(Card card) { System.out.println("Reissued: Transaction declined. This card is permanently deactivated."); } @Override public void blockCard(Card card) { System.out.println("Reissued: Cannot block a reissued card."); } @Override public void reissueCard(Card card) { System.out.println("Reissued: Card already reissued."); }}State: Transactions to Blocked and Reissued

BlockedState and ReissuedState.This new diagram emphasizes how the logic pivots within the pattern. While the Card object remains the same, the behavior completely shifts when the underlying state object changes from ActiveState to BlockedState. We implement the Decline Transaction and Reissue Card transitions identified in the original model.