Skip to content

design-patterns

8 Posts

How to Implement the Observer Pattern in Java (Java 21)

Build a stock-alert system with the observer pattern in Java 21: a thread-safe subject, lambda listeners, safe unsubscribe, and 16 checks that prove it works.

How to Implement the State Machine Pattern in Java

Build a parcel-tracking state machine in Java 21 with enums and a transition table, add a guard for failed deliveries, and prove the rules with 19 checks.

How to Implement the Strategy Pattern in Java (Java 21)

Replace a growing if/else chain with the strategy pattern in Java 21. A library late-fee calculator, built step by step, with lambdas, an EnumMap and 15 checks.