# java-design-patterns | Ilkka Seppälä | Knowledge Base | Instagit

Design patterns implemented in Java

GitHub Stars: 93.8k

Repository: https://github.com/iluwatar/java-design-patterns

---

## Articles

### [How to Combine Observer and Mediator Patterns for Complex Event Systems in Java](/iluwatar/java-design-patterns/how-to-combine-observer-and-mediator-patterns-for-complex-event-systems)

Learn how to combine Observer and Mediator patterns in Java. Route subject notifications via a Mediator hub to coordinate Observers and eliminate direct dependencies in complex event systems.

- Tags: deep-dive
- Published: 2026-02-27

### [How to Implement CQRS Pattern for Command and Query Separation in Java](/iluwatar/java-design-patterns/how-to-implement-cqrs-pattern-for-command-and-query-separation)

**The Command Query Responsibility Segregation (CQRS) pattern splits application logic into two distinct layers: commands that mutate state within transactions, and queries that execute read-only operations returning lightweigh...

- Tags: 
- Published: 2026-02-27

### [How to Implement the Unit of Work Pattern for Transaction Management in Java](/iluwatar/java-design-patterns/how-to-implement-unit-of-work-pattern-for-transaction-management)

**The Unit of Work pattern groups multiple database operations into a single atomic transaction that executes only when you explicitly call `commit()`, ensuring data consistency by delaying persistence until all business rules ...

- Tags: 
- Published: 2026-02-27

### [How to Implement Repository Pattern for Data Access Abstraction in Java](/iluwatar/java-design-patterns/how-to-implement-repository-pattern-for-data-access-abstraction)

Learn to implement the Repository pattern in Java. Isolate domain logic from data access using a collection-like interface for CRUD operations with Spring Data JPA.

- Tags: how-to-guide
- Published: 2026-02-27

### [How to Implement the Dependency Injection Pattern for Loose Coupling in Java](/iluwatar/java-design-patterns/how-to-implement-dependency-injection-pattern-for-loose-coupling)

Learn how to implement the Dependency Injection pattern in Java to achieve loose coupling. Swap implementations easily without modifying existing code and improve maintainability.

- Tags: how-to-guide
- Published: 2026-02-27

### [How to Implement the Null Object Pattern to Avoid Null Checks in Java](/iluwatar/java-design-patterns/how-to-implement-null-object-pattern-to-avoid-null-checks-in-java)

Implement the Null Object Pattern in Java to eliminate null checks. Learn how to replace null references with stateless, do-nothing implementations for safer code.

- Tags: how-to-guide
- Published: 2026-02-27

### [How to Implement the Template Method Pattern for Algorithm Frameworks in Java](/iluwatar/java-design-patterns/how-to-implement-template-method-for-algorithm-framework-definition)

Learn to implement the Template Method pattern in Java for algorithm frameworks. Define algorithm skeletons and reuse code effectively with this GoF design pattern.

- Tags: how-to-guide
- Published: 2026-02-27

### [How to Implement Adapter Pattern for Legacy System Integration in Java](/iluwatar/java-design-patterns/how-to-implement-adapter-pattern-for-legacy-system-integration)

Implement the Adapter pattern for legacy system integration in Java. Learn to create a wrapper class enabling seamless interoperability with legacy code without modification.

- Tags: how-to-guide
- Published: 2026-02-27

### [How to Implement the Facade Pattern for Simplified API Interfaces in Java](/iluwatar/java-design-patterns/how-to-implement-facade-pattern-for-simplified-api-interfaces)

Learn to implement the Facade pattern in Java to simplify complex API interfaces. Encapsulate multistep operations behind intuitive methods for cleaner code.

- Tags: how-to-guide
- Published: 2026-02-27

### [How to Implement the Iterator Pattern Using Java Generics](/iluwatar/java-design-patterns/how-to-implement-iterator-pattern-using-java-generics)

Learn to implement the Iterator pattern in Java using generics for type-safe, reusable collection traversal without exposing internal structure. Master this essential design pattern.

- Tags: tutorial
- Published: 2026-02-27

### [How to Implement the Memento Pattern for State Snapshot and Restoration in Java](/iluwatar/java-design-patterns/how-to-implement-memento-pattern-for-state-snapshot-and-restoration)

Learn to implement the Memento pattern in Java for effortless state snapshot and restoration. Capture and restore object states without exposing internal details.

- Tags: how-to-guide
- Published: 2026-02-27

### [How to Implement the Flyweight Pattern for Memory-Efficient Object Pools](/iluwatar/java-design-patterns/how-to-implement-flyweight-pattern-for-memory-efficient-object-pools)

Learn how to implement the Flyweight pattern for memory-efficient object pools. Reduce memory consumption by sharing immutable objects and support massive object counts without heap growth.

- Tags: how-to-guide
- Published: 2026-02-27

### [How to Implement the Composite Pattern for Hierarchical Object Structures in Java](/iluwatar/java-design-patterns/how-to-implement-composite-pattern-for-hierarchical-object-structures)

Implement the Composite pattern in Java to manage hierarchical object structures uniformly. Treat individual objects and compositions the same with a common interface.

- Tags: how-to-guide
- Published: 2026-02-27

### [How to Implement Chain of Responsibility for Request Handling Pipelines in Java](/iluwatar/java-design-patterns/how-to-implement-chain-of-responsibility-for-request-handling-pipelines)

Implement Chain of Responsibility in Java to build flexible request handling pipelines. Decouple senders from receivers and pass requests through a sequence of handlers.

- Tags: how-to-guide
- Published: 2026-02-27

### [How to Implement the Builder Pattern with a Fluent Interface in Java](/iluwatar/java-design-patterns/how-to-implement-builder-pattern-with-fluent-interface-in-java)

Learn to implement the Builder pattern with a fluent interface in Java. Leverage method chaining and validation for creating immutable objects efficiently.

- Tags: how-to-guide
- Published: 2026-02-27

### [How to Implement the Visitor Pattern Without Violating Encapsulation in Java](/iluwatar/java-design-patterns/how-to-implement-visitor-pattern-without-violating-encapsulation-in-java)

Learn how to implement the Visitor pattern in Java while preserving encapsulation. Discover techniques to keep fields private and maintain a stable interface for secure visitor interactions.

- Tags: deep-dive
- Published: 2026-02-27

### [How to Implement the State Pattern for Object Behavior Transitions in Java](/iluwatar/java-design-patterns/how-to-implement-state-pattern-for-object-behavior-transitions-in-java)

Learn to implement the State pattern in Java. This design pattern lets objects change behavior at runtime, simplifying complex conditional logic with state-specific classes.

- Tags: how-to-guide
- Published: 2026-02-27

### [How to Implement the Proxy Pattern for Lazy Initialization in Java](/iluwatar/java-design-patterns/how-to-implement-proxy-pattern-for-lazy-initialization-in-java)

Implement the Proxy pattern for lazy initialization in Java. Delay expensive object creation until needed, conserving resources effectively.

- Tags: how-to-guide
- Published: 2026-02-27

### [How to Implement the Decorator Pattern for Dynamic Feature Addition in Java](/iluwatar/java-design-patterns/how-to-implement-decorator-pattern-for-dynamic-feature-addition-in-java)

Dynamically add features to Java objects at runtime using the Decorator pattern. Learn how to extend behavior without modifying original code and avoid subclass explosions.

- Tags: how-to-guide
- Published: 2026-02-27

### [How to Implement the Command Pattern with Undo/Redo Functionality in Java](/iluwatar/java-design-patterns/how-to-implement-command-pattern-with-undo-redo-functionality-in-java)

Learn to implement the Command pattern with undo/redo in Java using Deque stacks. Discover how toggle commands reverse effects with this practical example from java-design-patterns.

- Tags: how-to-guide
- Published: 2026-02-27

### [How to Implement the Strategy Pattern for Runtime Algorithm Selection in Java](/iluwatar/java-design-patterns/how-to-implement-strategy-pattern-for-runtime-algorithm-selection-in-java)

Learn how to implement the Strategy pattern in Java for dynamic runtime algorithm selection. Encapsulate interchangeable algorithms and switch implementations effortlessly.

- Tags: how-to-guide
- Published: 2026-02-27

### [How to Implement the Observer Pattern Using Java PropertyChangeSupport](/iluwatar/java-design-patterns/how-to-implement-observer-pattern-using-java-propertychangesupport)

Implement the Observer pattern in Java using PropertyChangeSupport. Effortlessly manage listeners and fire change events with old and new values for robust notifications.

- Tags: how-to-guide
- Published: 2026-02-27

### [Factory Method vs Abstract Factory Pattern in Java: When to Use Each](/iluwatar/java-design-patterns/when-to-use-factory-method-vs-abstract-factory-pattern-in-java)

Learn when to use Java's Factory Method vs Abstract Factory patterns. Delegate product creation to subclasses with Factory Method or build families of related objects with Abstract Factory.

- Tags: comparison
- Published: 2026-02-27

### [How to Implement a Thread-Safe Singleton with Double-Checked Locking in Java](/iluwatar/java-design-patterns/how-to-implement-thread-safe-singleton-with-double-checked-locking-in-java)

Implement a thread-safe Singleton in Java using double-checked locking. Learn how volatile and synchronized blocks ensure lazy initialization with minimal overhead. Optimize your concurrent code now.

- Tags: how-to-guide
- Published: 2026-02-27

